Json Meteor在客户端集合中插入日期或时间戳

Json Meteor在客户端集合中插入日期或时间戳,json,mongodb,date,meteor,isodate,Json,Mongodb,Date,Meteor,Isodate,我原本期望一个带有日期属性的对象在Mongo中作为来自客户端或服务器端的ISODate保存,但事实并非如此 当我这样做的时候 if (Meteor.is_client()){ Collection.insert({text : "Client", number : 1, date : new Date() }); Collection.insert({text : "Client", number : 2, date : (new Date()).getTime() }); }

我原本期望一个带有日期属性的对象在Mongo中作为来自客户端或服务器端的ISODate保存,但事实并非如此

当我这样做的时候

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() });
}
在mongo,它像这样保存

{_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) 

有没有办法从客户端将带有日期属性的对象保存为ISODate?

对我来说,我不从客户端发送时间戳。相反,我在通过
Collection.allow
auth
branch下的函数插入时修改了文档

我认为这样做有几个好处-

  • 客户端不需要插入日期字段,这样可以保存代码

  • 时间戳基于服务器时间,而不是客户端时间, 这应该更准确

  • 最后,字段值是ISODate,而不是string。(憎恨 不支持本机日期类型的JSON)


是的,您给出的所有理由都是正确的,我在服务器上实现了一个钩子,因此每次对这些集合发出插入或更新请求时,创建和修改的日期都会添加到对象中。但在本例中,我想实现客户端。您最好使用deny,因为它总是运行的。可以有多个allow回调,如果其中一个返回true,那么另一个allow回调将不会运行,这意味着您的代码可能会被神秘地跳过。无论如何,使用否认是一个黑客攻击,一个更好的解决方案即将到来:我会认为这是流星中的一个错误,或者是流星使用的另一个部件。已为其记录问题: