1.获取时间到日
https://blog.csdn.net/li521wang/article/details/86566595
db.purchase_history.find().forEach(
function(item){
var ds= db.purchase_history.find({"_id":item._id},{“createTime”:1});
var dschilds=ds.toArray();
var temp = dschilds[0].createTime;
var id = dschilds[0]._id;
function tran_val(val){
if(val<10){
val=“0” +val;
}
return val;
}
var datenew = new Date(temp);
var year=datenew.getFullYear();
var month=tran_val(datenew.getMonth()+1);
var date=tran_val(datenew.getDate());
var datestr=year+""+month+""+date;
db.purchase_history.update({"_id": id},{$set:{“completedate” :datestr}},true);
}
)
2.实例
var t = db.getCollection(‘表1’).find({checkStatus:{$ne:null}});
t.forEach(function (item){
item.flag=“1”;
var i=item;//非常重要,否则会报错undefined,=null也不行
db.getCollection('表2').save({“键”:“值”,“键”:“值”});
})