mongodb - Mongo DB update query throwing error -
i have been trying update 1 filed using update query has throwing error , please help.
query: db.dumpbasiccompany.update( db.dumpbasiccompany.aggregate([{ $lookup: { from: "basiccompany", localfield: "companyname", foreignfield: "companyname", as: "inventory_docs"}},{ $project : {"_id":1 } } ]), { $set:{ flag: 1 } }) error: writeresult({ "nmatched" : 0, "nupserted" : 0, "nmodified" : 0, "writeerror" : { "code" : 2, "errmsg" : "cannot compare undefined" } })
i new people of mongo db not sure , kindly validated query.
you can use code this:
db.basiccompany.find().foreach( function(doc) { var check = false; data = db.dumpbasiccompany.find({ companyname: doc.companyname }).foreach(function(mydoc) { if (mydoc != null) { check = true; } }) if (check == true) { db.basiccompany.update({ _id: doc._id }, { $set: { flag: 1 } }); } });
Comments
Post a Comment