Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I systematically add a time stamp to new documents in Meteor?

Tags:

meteor

When a new document is inserted into a Collection, I'd like to add a time stamp to it. I want the server to do this, not the client. What is the best solution here?

Rem: I'd rather not implement my own custom Meteor.methods() for this, but use the classical Meteor.Collection.insert() method

like image 472
Ze Jibe Avatar asked Feb 17 '23 15:02

Ze Jibe


1 Answers

from here - https://github.com/oortcloud/unofficial-meteor-faq

Blockquote

How can I alter every document before it is added to the database?

There isn't support for this right now, but you can use a deny to achieve what you want on the server. For example, to timestamp each document as it goes into mongo:

Posts.deny({
  insert: function(userId, doc) {   
   doc.createdAt = new Date().valueOf();   
   return false; 
}}) 

```

like image 112
nate-strauser Avatar answered Apr 30 '23 04:04

nate-strauser