Created
April 5, 2017 14:35
-
-
Save m-x-k/02437cfa47d4e979d2e5ece63c52f7a6 to your computer and use it in GitHub Desktop.
Mongo update across databases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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