-
-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to insert current date in document #95
Comments
Please check if this answers your question: #89 |
In this answer we passing date from client. I want to insert mongo server's current date as do at shell with $currentDate. |
if you want restheart to add a time stamp you can rely on Representation Tranformers There is a ready to use transformer called addRequestProperties that allows you to inject some useful properties to write requests. Specifically you can add the dateTime property that is the request date. Note that this solution is much more reliable if you want to make sure that the client doesn't alter somehow the timestamp. In fact using $currentDate is still controlled by the client who could send whatever value. You can read the documentation for more details, in summary you add the rts metadata property to the collection specifying the addRequestProperties transformer with scope "CHILDREN" and phase "REQUEST" and restheart will use it for the write requests on collection documents.
Now if you add a document to
Note that dateTime and epochTimeStamp are not of type $date though. You can easily create a custom transformer to fit your needs. |
regarding support for $currentDate and other field update operators I have created task https://softinstigate.atlassian.net/browse/RH-151 current master branch already contains a version that supports them on |
thanks for pointing out this. I added support for update operators to all resources/verbs. this improvement will be available in next release 1.2 Basically now you can do:
|
How to insert current date in document as like $currentdate in mongo
The text was updated successfully, but these errors were encountered: