Skip to content

Instantly share code, notes, and snippets.

@m-x-k
Created April 5, 2017 14:35
Show Gist options
  • Select an option

  • Save m-x-k/02437cfa47d4e979d2e5ece63c52f7a6 to your computer and use it in GitHub Desktop.

Select an option

Save m-x-k/02437cfa47d4e979d2e5ece63c52f7a6 to your computer and use it in GitHub Desktop.
Mongo update across databases
// Add employee.badge_number to matching person in another database collection
db.getSiblingDB('databaseA').getCollection('employees').find({}).forEach(function(employee1) {
db.getSiblingDB('databaseB').getCollection('people').update(
{"_id": employee1._id},
{
"$set": {
"badge_number": employee1.badge_number
}
}
)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment