mongo copy from one collection to another (on the same db)

后端 未结 7 541
暖寄归人
暖寄归人 2020-12-24 08:02

I have got mongo db called test and in this db two collections collection1 and collection1_backup. How to replace content of col

相关标签:
7条回答
  • 2020-12-24 08:40

    Better way would be to use .toArray()

     db.collection1.drop(); // Drop entire other collection
    
     // creates an array which can be accessed from "data"
     db.collection1_backup.find().toArray(function(err, data) {
    
          // creates a collection and inserting the array at once
          db.collection1.insert(data);
     });
    
    0 讨论(0)
提交回复
热议问题