您可以使用聚合查询和批量更新中的光标更新3.6版本中的匹配文档。
这是贝壳样品。
var bulk = db.colname.initializeUnorderedBulkOp();
var count = 0;
var batch = 50; // Change batch size as you need
db.colname.aggregate([
{$match : {$expr: {$ne:[ {$millisecond: "$date" },0]}}},
{$project:{
date:{$dateFromParts:{
year:{$year:"$date"},
month:{$month:"$date"},
day:{$dayOfMonth:"$date"}
}}
}}
]).forEach(function(doc){
bulk.find( {"_id" : doc._id}).updateOne(
{ "$set": {"date" : doc.date}}
);
count++;
if (count == batch) {
bulk.execute();
bulk = db.colname.initializeUnorderedBulkOp();
count = 0;
}
});
if (count > 0) {
bulk.execute();
}