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.