Reputation: 10696
How do I go about changing data (writing data) inside my .each
loop?
e.g.
var q = {}; // some query here
db.collection('somedata').find(query).each(function(err, doc) {
if(doc.flag === true) {
doc.anotherField = true; // change some data here??
}
});
Upvotes: 0
Views: 56
Reputation: 12975
First convert to array using toArray and then you can loop inside .
var q = {}; // some query here
db.collection('somedata').find(query).toArray(function(err, doc) {
if(err)throw err;
doc.forEach(function(eachDoc){
if(eachDoc.flag === true) {
eachDoc.anotherField = true; // change some data here??
}
});
});
Upvotes: 1