流星:更新文档时出错

Meteor: Error while updating document

更新对象日期时出错

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)

您试图在数据库中存储 Moment.js 对象而不是 Javascript 日期对象,您不能这样做。您需要像这样检索底层 JS 日期对象:

var newDue = moment(today).add(incBy,'days').toDate();