Skip to content

Instantly share code, notes, and snippets.

@sgnl

sgnl/mongo.js Secret

Last active October 1, 2015 00:18
Show Gist options
  • Save sgnl/f9a5cc2c4807f3d60dcc to your computer and use it in GitHub Desktop.
Save sgnl/f9a5cc2c4807f3d60dcc to your computer and use it in GitHub Desktop.
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