I need to merge two collections into one, but I need to put the document only if it doesn't exists in the first collection. How can I do it? What's the best way?
I saw something about agregation and mapreduce but I am not sure about what to use. Can you help me, please?
解决方案
I think there is no automatic way for that.
Assume u have 2 collection for merge, c1 and c2
You could manually do the merge with
db.c1.find().forEach(function(item) {
db.c2.insert(item);
db.c1.remove(item);
});
u should be careful with that because mongo does not support multi-document-transaction