Insert date or Meteor mark in customer collection

I expected that an object with a Date property would be saved in Mongo as ISODate from the client or server side, but this is not the case.

When i do

if (Meteor.is_client()){ Collection.insert({text : "Client", number : 1, date : new Date() }); Collection.insert({text : "Client", number : 2, date : (new Date()).getTime() }); } else { Collection.insert({text : "Server", number : 1, date : new Date() }); } 

In mongo it saves like that

 {_id : "xx-xx-xx-xx-xx", text : "Client", number : 1, date : "2012-08-21T18:40:47.446" } {_id : "xx-xx-xx-xx-xx", text : "Client", number : 2, date : 1345574805367 } {_id : "xx-xx-xx-xx-xx", text : "Server", number : 1, date : ISODate(2012-08-21T18:40:47.446) 

Is there a way to save an object with a Date property on the client side as ISODate?

+4
source share
1 answer

For me, I do not send timestamps from the client side. Instead, I modify the document when pasting through the Collection.allow function in the auth branch.

I think there are several advantages to this -

  • The client side should not insert a date field that stores the code.

  • The timestamp is based on server time, not on the client side, which should be more accurate.

  • And the last field value is ISODate, not a string. (Hate JSON without a native date type)

+4
source

All Articles