# Attach server side date while posting data in mongodb

**URL:** <https://community.dreamfactory.com/t/attach-server-side-date-while-posting-data-in-mongodb/2502>\
**Category:** Server-Side Scripting\
**Created:** [April 7, 2016, 1:14pm UTC](https://community.dreamfactory.com/t/attach-server-side-date-while-posting-data-in-mongodb/2502 "2016-04-07T13:14:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hedisam](https://avatars.discourse-cdn.com/v4/letter/h/b782af/32.png) [@hedisam](https://community.dreamfactory.com/u/hedisam)\
**Post date:** [April 7, 2016, 1:14pm UTC](https://community.dreamfactory.com/t/attach-server-side-date-while-posting-data-in-mongodb/2502/1 "2016-04-07T13:14:29Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![hedisam](https://avatars.discourse-cdn.com/v4/letter/h/b782af/32.png) [@hedisam](https://community.dreamfactory.com/u/hedisam)\
**Post date:** [April 24, 2016, 4:42pm UTC](https://community.dreamfactory.com/t/attach-server-side-date-while-posting-data-in-mongodb/2502/2 "2016-04-24T16:42:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![DFCommunityManager](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/dfcommunitymanager/32/887_2.png) [@DFCommunityManager](https://community.dreamfactory.com/u/DFCommunityManager)\
**Post date:** [June 29, 2016, 7:35pm UTC](https://community.dreamfactory.com/t/attach-server-side-date-while-posting-data-in-mongodb/2502/3 "2016-06-29T19:35:29Z")

</div>

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
