hi have two collections from two separate sources which i like to merge into one collection. both collections have one data entry called “name” that matches on both collections apart from that data is not the same.
i like to merger copy data from collection1 into collection2 with:
db.getCollection(“collection2”).aggregate([ {$merge:{ into:“collection1”, on:“name”, whenMatched: “replace”, whenNotMatched: “insert” }} ])
errors on:
“errmsg” : “Cannot find index to verify that join fields will be unique”,
database looks like this:
{ “_id” : ObjectId(“61643e7dbf5b6eee81501e11”), “name” : “example1”, “data1” : “example”}
{ “_id” : ObjectId(“61643e7dbf5b6e34545501345”), “name” : “example1”, “data1” : “example”}
i just want to match on “name” and then copy everything across that does not exist in collection2 from collection1 adding the extra data fields.
thanks for any tips on how to best to go about this thanks.