2022-05-06 | UNLOCK

MongoDB常用操作

批量替换

1
2
3
4
5
6
7
8
9
10
11
12
13
db.getCollection("content_291").find().forEach(
function (item) {
var arr = item.Category;
arr = arr.replace("DCMM评估师", "数据管理专业人士认证(CDMP)");
db.getCollection('content_291').update({
"_id": item._id
}, {
$set: {
"Category": arr
}
})
}
)

导入Mongo

1
2
3
mongorestore -h Node1  -u dguser1 -p 123456 -d dgcloud --gzip  --drop  /work/sql_backup/dgcloud

mongorestore -h 127.0.0.1:27017 --authenticationDatabase admin -u root -p password -d dgcloud --drop /home/dgcloud

登录Mongo

1
mongo -u dguser1 -p --authenticationDatabase dgcloud --host Node1

导出Mongo

1
mongodump -uroot -h 127.0.0.1:27017 --authenticationDatabase admin -d dgcloud -o /home/