xxxxxxxxxx
db.<SOURCE_COLLECTION>.aggregate([ { $match: {} }, { $out: "<TARGET_COLLECTION>" } ])
xxxxxxxxxx
db.collection_name.find().forEach(function(d){ db.getSiblingDB('target_db')['collection_in_target'].insert(d); });
Where
collection_name is source collection to be copied
target_db is the target database to copy a collection to.
collection_in_target will be name in target database.
xxxxxxxxxx
// copy one mongodb collection to another
db.<SOURCE_COLLECTION>.aggregate([ { $match: {} }, { $out: "<TARGET_COLLECTION>" } ])