近期在搭建开发环境时需要用到部分生产数据用于测试,单独作一篇文章来记录相关命令。
在 Ubuntu 22.04 上,mongo-tools
包可能不可用。可以直接安装 MongoDB 客户端工具,它们包含了 mongoexport
工具。以下是安装步骤:
wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
sudo apt update
sudo apt install -y mongodb-org-tools
mongoexport --uri="mongodb://localhost:27017" --db=mydatabase --collection=mycollection --out=output.json
mongodump --uri="mongodb://localhost:27017" --db=mydatabase --out=output
mongodump --uri="mongodb://localhost:27017" --out=output
mongoimport --uri="mongodb://localhost:27017" --db=mydatabase --collection=mycollection --file=output.json
mongorestore --uri="mongodb://localhost:27017" --db=mydatabase --drop output/mydatabase
mongorestore --uri="mongodb://localhost:27017" --drop output
E11000 duplicate key error collection
在导入数据时,如果数据库中已经存在相同的 key,可以使用 --drop
参数来删除已有数据。
在导入数据时,如果数据库已经存在,可以使用 --drop
参数来删除已有数据库。在导出数据时,可以使用 --query
参数来指定导出条件。
connection() error occurred during connection handshake: auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed.
这是因为 MongoDB 4.0 之后默认使用了 SCRAM-SHA-1 认证方式,而之前的版本使用了 MONGODB-CR 认证方式。可以在连接字符串中指定认证方式:
mongoimport --uri="mongodb://localhost:27017" --authenticationDatabase=admin --drop output
完整教程:如何下载shadowrocket以及常见问题解答最新Shadowsocks免费下载暗网中文论坛:概念、特点、使用方法和常见问题详解TikTok翻墙完整指南在CentOS上安装和配置Shadowsocks-Go教程2024 年 4 月 26 日可用!Libgen 镜像网址分享,助力网络兼职者获取优质资源【新手指南】国内如何看Netflix/奈飞/网飞12月4日起,印象笔记Evernote限制免费用户最多创建 50 个笔记搜索引擎查找 Ollama 本地部署的 DeepSeek,实现免费 AI 运行跑路机场名单Clash节点名词解密:机场推荐与一元机场Thse 机场怎么样?跑路了!