0

I am using aggregation framework to to migrate data from one collection to another. The following is the sample of code:

db.oldCollection.aggregate([{$out : "newCollection"}])

The indexes from oldCollection will not copied in newCollection is already known.

But is there any way easiest I can move this directly to a different database in on the same MongoDB host and is there any option to stop overwriting/replacing the entire data in the collection. I mean to retain changes made on the newColleciton?

As per MongoDB docs:

$out stage atomically replaces the existing collection with the new results collection. The $out operation does not change any indexes that existed on the previous collection.

Amol M Kulkarni
  • 21,143
  • 34
  • 120
  • 164

1 Answers1

0

I don't think it's possible. If you really want to export to other database; save the intermediate result somewhere and populate by creating another database which seems a headache though