Merging two collections?

Is $merge (aggregation) the best way to go about merging two collections?

Some how I ended up with two collections for the same entity. The original table is called “clients” the new table is called “customers”. My application created and started populating the “customers” collection after i migrated my entire server application to NestJs.

Hello @Miguel_Escamilla, the $merge aggregation stage allows incorporating the aggregation’s output into another collection. This will be a complete server side operation - which is efficient. Also, the aggregation stages allow any required data transformation before it can be merged. The merge has options like “whenMatched” and “whenNotMatched” - which are useful to customize the merge operation.

You can also export from one collection into a JSON/CSV and import back into another collection - using mongoexport and mongoimport command-line tools. Another option is to write a custom application program using your favorite driver (e.g., Java, NodeJS, etc.) to do the merge process.