【发布时间】:2015-09-16 04:16:14
【问题描述】:
我想运行一个查询,获取所有具有“活动”字段为真的文档,并在它们上运行一个自定义函数,检查文档中的“日期”字段是否早于 10 天。如果它们都为真,那么它将使活动字段为假。
这是我当前代码的样子:
db.ad.find( { $and : [ // Check if active is true and the $where clause also equals to true
{ 'active' : true
},
{ '$where' : function() { // Custom compare function
var date = new Moment(this.date); // gets the date from the current document
var date2 = new Moment();
return Math.abs(date.diff(date2, 'days')) > 10;
}
}
]},
function(err, result) {
// How to update the document here?
}
);
谁能告诉我在查找查询后如何更新文档?
【问题讨论】: