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
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;
}})
```
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With