You are on page 1of 4

MongoDB organizes data on the database, collection, and document levels.

Remember, MongoDB
itself doesn’t enforce a schema, but every application needs some basic internal standards about
how its data is stored.
1. Download mongodb software link

Đọc tài liệu https://docs.mongodb.com/manual/


2. Cài đặt và cấu hình

1
Download database-tools link

Giải nén và copy nội dung trong thư mục bin vào trong thư mục C:\MongoDB\Server\5.0\bin.
Start MongoDB Server:

2
Thiết lập biến môi trường
Click chuột phải trên “This PC”  chọn Properties

The mongo shell has been deprecated in MongoDB v5.0. The replacement is mongosh.
Download và cài đặt mongosh link
Điều kiện trước: Để sử dụng MongoDB Shell, phải có triển khai MongoDB để kết nối.
Sử dụng mongosh với localhost và default port 27017

3
3. Một số thao tác cơ bản
MongoDB Backup
Có thể dùng các cú pháp sau (localhost, default port 27017)
mongodump -d db_name -o dest_folder
mongodump --db db_name --out dest_folder
Trong đó,
-d/--db : tên db cần backup
-o/--out : đường dẫn thư mục sẽ chứa dữ liệu đích.
Một ví dụ:
mongodump -d projectdb -o "D:\JSondata"
MongoDB Restore
Có thể dùng các cú pháp sau (localhost, default port 27017)
mongorestore --drop dump/
Xóa db cũ và restore tập các collection của các database trong thư mục dump
mongorestore --drop --nsInclude=testdb.* dump/
Xóa và restore tất cả các collection có trong db testdb, trong thư mục dump
mongorestore --drop --nsInclude=testdb.orders dump/
Xóa collection orders cũ, và restore collection orders trong db tetdb, trong thư mục
dump
MongoDB Import
Một ví dụ (localhost, default port 27017)
mongoimport --db testdb --collection players --file players.json
MongoDB Export
Một ví dụ (localhost, default port 27017)
mongoexport -d testdb -c players -o players.json

You might also like