- MongoDB Administrator’s Guide
- Cyrus Dasadia
- 187字
- 2021-07-02 15:47:44
How to do it...
- Start the mongod daemon to explicitly use MMAPv1 storage engine:
/data/mongodb/bin/mongod --dbpath /data/db --storageEngine mmapv1
- Start the mongo client and you should be presented with the MongoDB shell. Execute the following commands in the shell:
> var status = db.serverStatus()
> status['storageEngine']
{
"name" : "mmapv1",
"supportsCommittedReads" : false,
"readOnly" : false,
"persistent" : true
}
- Now let's add some random data into it. Run the following JavaScript code to insert 100 documents with random data:
> use mydb
> for(var x=0; x<100; x++){
db.mycol.insert({
age:(Math.round(Math.random()*100)%20)
})
}
> db.mycol.count()
100
- Exit the shell and perform a full backup using mongodump command:
mkdir /data/backup
mongodump -o /data/backup --host localhost:27017
- Now shutdown the mongod process.
- Create a new data directory for the migration and start the mongod daemon with a new storage engine:
mkdir /data/newdb
/data/mongodb/bin/mongod --dbpath /data/newdb --storageEngine wiredTiger
- Let's restore the previous backup to this new instance:
mongorestore /data/backup/
- Start the mongo shell and check your data:
> var status = db.serverStatus()
> status['storageEngine']
{
"name" : "wiredTiger",
"supportsCommittedReads" : true,
"readOnly" : false,
"persistent" : true
}
> use mydb
switched to db mydb
> db.mycol.count()
100
推薦閱讀
- 深入理解Bootstrap
- Redis入門指南(第3版)
- 動手玩轉Scratch3.0編程:人工智能科創教育指南
- Java從入門到精通(第5版)
- Network Automation Cookbook
- 面向STEM的Scratch創新課程
- ServiceNow:Building Powerful Workflows
- Learning Node.js for .NET Developers
- 分布式數據庫HBase案例教程
- Software Architecture with Python
- RESTful Web API Design with Node.js
- GO語言編程從入門到實踐
- 面向物聯網的Android應用開發與實踐
- Mastering Wireless Penetration Testing for Highly Secured Environments
- Mastering Rust