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

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

    You can use a simple command to Backup MongoDB Collection. It will work only on MongoDB 4.0 or earlier versions.

    db.sourceCollectionName.copyTo('targetCollectionName')
    

    Your targetCollectionName must be in Single(') or Double(") Quote

    Note:

    The db.collection.copyTo() method uses the eval command internally. As a result, the db.collection.copyTo() operation takes a global lock that blocks all other read and write operations until the db.collection.copyTo() completes.

提交回复
热议问题