在 Linux 下导入 MongoDB 配置,通常分 两种场景:
mongorestore 导入数据库适用于 .bson / dump 文件
mongorestore --uri="mongodb://用户名:密码@127.0.0.1:27017" /path/to/dump
或指定数据库:
mongorestore -d 数据库名 /path/to/dump/数据库名
常用参数:
--drop # 导入前删除原有集合
--gzip # 如果是压缩文件
mongoimport 导入 JSON / CSV适用于配置文件、初始化数据
JSON 导入
mongoimport \
--db 数据库名 \
--collection 集合名 \
--file data.json \
--jsonArray
CSV 导入
mongoimport \
--db 数据库名 \
--collection 集合名 \
--type csv \
--headerline \
--file data.csv
一般路径:
/etc/mongod.conf
示例配置:
storage:
dbPath: /var/lib/mongo
systemLog:
destination: file
path: /var/log/mongodb/mongod.log
net:
bindIp: 0.0.0.0
port: 27017
mongod -f /etc/mongod.conf
systemctl restart mongod
sudonet.port--authenticationDatabase如果你指的是 “导入某个 MongoDB 配置(如集群、用户、角色)”,可以告诉我具体场景,我可以给你更精确的命令。