Created
November 15, 2018 19:18
-
-
Save avoidwork/7ea182c5fbfb014b891ad205cd580502 to your computer and use it in GitHub Desktop.
MongoDB flatten aggregation & update
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
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