Reputation: 75
I have a MongoDB database with 2 collections:
All changes to groups are done by changing the members array of the group to include the users ids.
I want to sync these changes across to the users collection by using map/reduce. How can I output the results of map/reduce into an existing collection (but not merging or reducing).
My existing code is here: https://gist.github.com/morgante/5430907
Upvotes: 4
Views: 518
Reputation: 45287
How can I output the results of map/reduce into an existing collection
You really can't do it this way. Nor is this really suggested behaviour. There are other solutions:
Solution #1:
Honestly, this is a safe way to do this. You can implement some basic retry logic in the whole loop.
Solution #2:
This solution may require a separate piece (the queue), but any large system is going to have such denormalization problems. So this will not be the only place you see this.
Upvotes: 2