MongoDB current date in save method - javascript

How to make MongoDB fill a field with current UTC DateTime on save method?
I know there is $currentDate operator, but it's only available in update method.

It sounds like you're trying to get access to the time on the mongo server for the insert, right? Mongo _ids encode the timestamp of their creation -- would that work for your needs? https://docs.mongodb.com/manual/reference/method/ObjectId/
Otherwise, I think you might need to provide a date from your application code.

Related

timestamp in firebase/firestore

When I save timestamp dates on firestore, it saves as a timestamp datatype.
But when I retrieve the data into React, sometimes it is retrieved as a timestamp and I can convert it to JS date using toDate() but other times is retrieved as {_seconds, _nanoseconds} and I need to convert it manually.
It seems very confusing. Is there a best practise about how to save and how to retrieve dates from Google Firestore?
Thanks
The only way to store dates in Firestore is through the Timestamp, you could store them through Strings, but it would be a huge pain to convert it back to Date so there really isn't any other better way to do it, unfortunately.

How input date as string in javascript client, pass to python server, and store as datetime in myql?

I want my users to input date as a string.
The date is passed via a Python backend to a MySQL database where it is stored as datetime.
What is a way of doing this? To clarify, I am asking what kinds of conversions I should do, where, and using what packages.
Now a lot of things in this domain depends on your use-case but I'll take a shot. I'm guessing you pass your data to the server after JSON.stringifying it?
Now we have data on the server. You get everything as json strings, do a json loads and convert them to python strings(unicodes) on your server. From here on, things are easy except for one single problem
You'll have to know the format of your date beforehand
Why?
Because you'll have to do a strptime on your date. A simple example of converting a string date to datetime object is -
from datetime import datetime
dt = datetime.strptime("21/11/06 16:30", "%d/%m/%y %H:%M")
# strptime("date string", "format of date")
The example can be found just below this.
The format table can be found here (which is quite handy, I'd bookmark it)
I hope that makes some if not complete sense

Update couch db docment date format

Is there way I can update all the date field format existing in documents of couch db
change format from
DateTime : "07-29-2017 19:07:23"
to
DateTime : "2017-07-29 19:07:23"
There's no automated way to do this, aside from writing a script that updates each of your documents.
An alternative, depending on your exact situation, might be to use a view to manipulate the data as it's being read. The view could detect the existing date format, and if it's the old one, convert it before displaying the document.
This would change the way you query the data, though--you'd have to request the new view, which could obviously be a deal-breaker in some scenarios.
First, you need a way to apply a function to every document. To do so, I suggest that you use pouchdb-migrate.
Finally, you only have to define your function and integrate it into pouchdb-migrate. You can either parse the date and convert it or simply do some string manipulation.

Schema Field Type for Date.now() in Meteor-Simple-Schema

In my Meteor app I'm using Date.now() to create a timestamp for using in a new document that I'm inserting into Mongodb. Date.now() seems very well suited for my app. However I'm not very familiar with handling dates and times.
Now that I'm making the switch to aldeed:simple-schema, is it best practice to use Date.now() or convert it to another format? For the schema type, do we use datetime or datetime-local?
I would use datetime-local, however in order to do that you will have to access the Date() objects setters and set the objects value to the current local time of your area. Check out this - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

Azure Mobile Services : Get Server DateTime and compare it

I want to run a scheduled job every 10 minutes which will do the following:
Check the table records and delete those who hasn't been updated for 10 minutes.
How is it possible to get the current server date in javascript in order to compare it?
Use the JavaScript Date object. Just creating a new Date object without parameters will give you the server date and time. It will of course be in GMT as all the servers in Azure run on GMT. However, be aware of clock drift. Each of the servers could be slightly off from one another time wise, so it may not be exact if comparing times across servers.
var cutOfDate = new Date();
You could also load up one of the JavaScript data libraries like Moment or something like that as well if you need to do a lot of date formatting or evaluations.
Another option is to simply have a stored procedure that is called to perform your clean up for you. The stored procedure could then use the SQL GETDATE() to determine the current date and do the deletes based on that.
I think what you want is this. Giving you an overview:
http://azure.microsoft.com/en-us/documentation/articles/mobile-services-how-to-use-server-scripts/#access-tables
For date and time
http://azureinmycloud.net/2011/10/26/working-with-datetime-now-in-windows-azure-apps/

Categories