I'd like to copy data from one collection (collection A) into another (collection B) using MongoDB. I'd also like to keep the existing data in collection A. [I'm using MongoDB shell version v4.4.3, GoormIDE with a Node.js and Express app)
From what I understand the $merge operator will be the most appropriate, however I keep running into an error. I have been using the code below:
db.getSiblingDB("<databasename>").<sourcecollection>.aggregate( [ { $match : {} }, { $merge : "<destinationnewcollection>" } ] )
This is the resulting error:
uncaught exception: Error: command failed: {
"ok" : 0,
"errmsg" : "Failed to retrieve database or collection name from $merge. err=Error parsing $merge value.
"code" : 8000,
"codeName" : "AtlasError"
} : aggregate failed :
Other operators such as add seem to work fine so I am lost for ideas on this one. Any ideas of what I'm doing wrong?