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

后端 未结 7 543
暖寄归人
暖寄归人 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:16

    simply just do this.

    //drop collection1

    db.collection1.drop();
    

    //copy data from collection1_backup to collection1

    db.collection1.insert(db.collection1_backup.find({},{_id:0}).toArray());
    

提交回复
热议问题