// Fill out a literal array of collections you want to duplicate the records in.

// Iterate over each collection using the forEach method on the array.

// For each collection get (find) all the records and forEach on each of them.

// Remove the _id field from each record as MongoDB will generate this for you and

// you can't have a duplicate.

// Save the record.

// This assumes that the collection does not have any unique keys set on any of the

// other fields.

// Run this in the MongoDB shell

 

[db.<collection1>, db.<collection2>].forEach(function(collection)

{

    collection.find({}).forEach(function(x) {

     delete x._id;

     collection.save(x);

    });

});

 

From: https://gist.github.com/guyellis/9948194

posted on 2018-01-26 10:57  今夜太冷  阅读(192)  评论(0编辑  收藏  举报