我在更新对象的日期时遇到错误
Template.showCards.events({
...
},
'click #difficulty button': function(event) {
var incBy = event.target.value;
var today = moment();
var newDue = moment(today).add(incBy,'days');
Cards.update(
this._id, {
$set: {due: newDue}
}
);
}
});
知道为什么吗?
Meteor更新了正确的due
字段,但值变为"Invalid date"
。
以下是完整错误(Chrome开发工具):
Exception while simulating the effect of invoking '/cards/update' Error: Sorting not supported on regular expression {stack: (...), message: "Sorting not supported on regular expression"} Error: Sorting not supported on regular expression
at Error (native)
at Object.LocalCollection._f._cmp (http://localhost:3000/packages/minimongo.js?e8806aa7782b729b2517ebc0cd10b321667f1427:2411:13)
at Object.LocalCollection._f._cmp (http://localhost:3000/packages/minimongo.js?e8806aa7782b729b2517ebc0cd10b321667f1427:2386:36)
at Object.LocalCollection._f._cmp (http://localhost:3000/packages/minimongo.js?e8806aa7782b729b2517ebc0cd10b321667f1427:2378:33)
at Object.LocalCollection._f._cmp (http://localhost:3000/packages/minimongo.js?e8806aa7782b729b2517ebc0cd10b321667f1427:2386:36)
at Object.LocalCollection._f._cmp (http://localhost:3000/packages/minimongo.js?e8806aa7782b729b2517ebc0cd10b321667f1427:2378:33)
at http://localhost:3000/packages/minimongo.js?e8806aa7782b729b2517ebc0cd10b321667f1427:1838:54
at http://localhost:3000/packages/minimongo.js?e8806aa7782b729b2517ebc0cd10b321667f1427:1474:21
at Array.some (native)
at Function._.some._.any (http://localhost:3000/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:284:59)
答案 0 :(得分:1)
您尝试在数据库中存储Moment.js对象而不是Javascript日期对象,而您无法做到这一点。您需要检索基础JS日期对象,如下所示:
var newDue = moment(today).add(incBy,'days').toDate();