The find()
function returns a cursor
, you need to iterate:
When the find () method returns documents, the method actually returns the cursor to the documents
Your code has been updated:
db.ratings.find().forEach(function(doc){ db.items.find({_id: doc.item_id}).forEach(function(item){ var ry = item.detail.ry; db.ratings.update(doc,{$set: {itd: ry}}); }) })
or you can use findOne()
, which returns one of the relevant documents.
db.ratings.find().forEach(function(doc){ var item = db.items.findOne({_id: doc.item_id}) var ry = item.detail.ry db.ratings.update(doc,{$set: {itd: ry}}) })
source share