Yet another MongoDB one-liner!
db.jobs.find({ "merchant_id" : { $exists: false }, }).forEach( function(myDoc) { cid = db.customers.findOne({"_id": myDoc.customer_id}); myDoc.merchant_id = cid.merchant_id; db.jobs.save(myDoc) } )
I'm feeling good about these one-liners - really easy to work with batch updating in MongoDB!
Somehow we lost the merchant_id field for a number of documents - 101 to be exact - and I wanted to update these documents by relying on a similar field in a related document from a different collection.
Easy-as with Mongo