美文网首页
MongoDB - Database/Collection 复制

MongoDB - Database/Collection 复制

作者: Anoyi | 来源:发表于2022-08-31 11:14 被阅读0次

MongoDB(Version 4.0+) 原生不支持 Database/Collection 的重命名操作,需要通过复制来实现。

Rename Database

Rename database test to examples

mongodump -u <username> -p <password> --authenticationDatabase admin --archive -d=test | mongorestore -u <username> -p <password> --authenticationDatabase admin --archive --nsFrom='test.*' --nsTo='examples.*'

Rename Collection

Rename collection test.user to school.student

mongodump -u <username> -p <password> --authenticationDatabase admin  --archive -d=test -c user | mongorestore -u <username> -p <password> --authenticationDatabase admin  --archive --nsFrom='test.user' --nsTo='school.student'

相关文章

网友评论

      本文标题:MongoDB - Database/Collection 复制

      本文链接:https://www.haomeiwen.com/subject/puhdnrtx.html