-
-
Save sgnl/f9a5cc2c4807f3d60dcc to your computer and use it in GitHub Desktop.
This file contains 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
var results = db.collection.find(); | |
results.forEach(function(doc) { | |
var newColorList = []; | |
Object.keys(doc).forEach(function(key) { | |
if (key !== 'name' || key !== '_id') { | |
if (doc[key] === 1) { | |
newColorList.push(key) | |
} | |
} | |
}); | |
if (newColorList.length) { | |
db.colorCollection.findAndModify({ | |
query: { _id: doc._id }, | |
update: { $set: { "colors": newColorList } }, | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment