MongoDB Basics: Data Model, User Creation, Service Setup, and Backup/Restore Commands
This article explains MongoDB's document-oriented data model, shows how to create an admin user, configure the mongod service on Linux, and provides detailed command‑line examples for backing up and restoring databases and collections using mongodump, mongorestore, mongoexport, and mongoimport.
MongoDB is a document database that stores data as JSON‑like documents; a document (Document) is analogous to a row, multiple documents form a collection (Collection), and collections belong to a database. In contrast, MySQL organizes data into databases, tables, rows, and columns.
To create an administrative user, run the Mongo shell and execute the following commands:
[root@localhost ~]$ mongo > use admin > db.createUser({ user: "admin", pwd: "123456", roles: [ { role: "root", db: "admin" } ] }) > quit()Configure the mongod service by editing /usr/lib/systemd/system/mongod.service (example snippet shown) and then reload and restart the service:
[root@localhost ~]$ systemctl daemon-reload [root@localhost ~]$ systemctl restart mongodThe backup and restore utilities accept several parameters:
--host // specify host name --port // specify port -u // username -p // password -d // database to backup/restore -c // collection to backup/restore -o // output directory for backupBackup examples:
mongodump --host 192.168.210.85 --port 27017 -u admin -p 123456 -o /tmp/alldb/ mongodump --host 192.168.210.85 --port 27017 -u admin -p 123456 -d mydb -o /tmp/mongobak/ mongodump --host 192.168.210.85 --port 27017 -u admin -p 123456 -d mydb -c clo1 -o /tmp/mongobak/ mongoexport --host 192.168.210.85 --port 27017 -u admin -p 123456 -d mydb -c clo1 -o /tmp/1.jsonRestore examples:
mongorestore --host 192.168.210.85 --port 27017 -u admin -p 123456 /tmp/alldb/ mongorestore --host 192.168.210.85 --port 27017 -u admin -p 123456 -d mydb /tmp/mongobak/ mongorestore --host 192.168.210.85 --port 27017 -u admin -p 123456 -d mydb -c clo1 /tmp/mongobak/mydb/clo1.bson mongoimport --host 192.168.210.85 --port 27017 -u admin -p 123456 -d mydb -c clo1 --file /tmp/1.json----------------------end---------------------
Recommended reading:
Project Practice – Docker Deploy JAR
LVS + Keepalived + Nginx High Availability
LVS Layer‑4 Load Balancing
Shell Script – case Statement
Company Need – DNS Master‑Slave Setup for Offline Test Environment
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Practical DevOps Architecture
Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
