我有一个称为Leads的集合,看起来像这样:
_id : 5dc11373345fac0bb44a6765
Rooms : "2"
Businessname : "Jason LLC"
PhoneNumber :"1111-4444-4444"
City : "Los Angeles"
supplier : 5dc1090b345fac0bb44a6761
LeadId : "976d1d7a-8725-49d7-b891-392c9da940af"
PublishDate : 2019-11-05T06:15:15.972+00:00,Duplicate : ""
然后使用InsertMany进入Leads
集合:
Leads.insertMany(leadsToInsert,{ ordered: false })
.then(function(docs) {
console.log("Number of documents inserted: " + docs.length);
return res
.status(200)
.json({ msg: "Documents uploaded to MongoDB Successfully!" });
})
.catch(function(err) {
// error handling here
console.log("Failed to insert Bulk..." + err.message);
return res.status(500).json({ msg: err.message });
});
唯一字段是PhoneNumber
,在InsertMany
之后,我想找到所有重复的文档,并使用新字段Duplicate
(布尔值True / False)更新这些文档。
我们如何在猫鼬中实现这一目标?