Attach server side date while posting data in mongodb


#1

I need to attach timestamp to messages which will be saved in MongoDB. How can I do that using server side scripting? How should I get server date?


#2

Here’s my attempt:

mongodb._table.tabletest.post.pre_process

var lodash = require("lodash.min.js");

if (event.request.payload.resource) {

    var resource = event.request.payload.resource;
    resource.timestamp = Date.now();
    
    // set this flag if you change the response content
    event.request.content_changed = true;
}

It may be useful for someone.


#3

Hey @hedisam thanks so much for replying with your solution! This will be very helpful for our community and I am glad to see that you figured it out.

Happy coding!
@AlexBowen