Skip to content

Instantly share code, notes, and snippets.

@avoidwork
Created November 15, 2018 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avoidwork/7ea182c5fbfb014b891ad205cd580502 to your computer and use it in GitHub Desktop.
Save avoidwork/7ea182c5fbfb014b891ad205cd580502 to your computer and use it in GitHub Desktop.
MongoDB flatten aggregation & update
new_recommended = db.profiles.aggregate([{$unwind: "$recommended"}, {$group: {_id : "$_id", recommended: {$push: "$recommended"}}}]).toArray();
new_recommended.forEach(function (x) {db.profiles.update({_id: x._id}, {$set: {recommended: x.recommended}})});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment