// 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

相关文章:

  • 2022-02-03
  • 2022-12-23
  • 2022-12-23
  • 2021-09-01
  • 2022-01-04
  • 2022-12-23
  • 2021-06-14
  • 2021-06-15
猜你喜欢
  • 2022-01-17
  • 2022-12-23
  • 2021-10-25
  • 2021-11-21
  • 2021-06-20
  • 2021-10-15
  • 2021-06-24
相关资源
相似解决方案