Một số câu lệnh cơ bản khi làm việc với mongoDB.
1. Tạo một database trong mongo:
mongo>use databasename
2. Hiện thị tất cả các database trong mongo:
mongo>show dbs
3. Copy database này sang database kia
mongo>db.copyDatabase('existed_databasename','new_databasename');
4. Xóa 1 database trong mongo
mongo>use databasename
mongo>db.dropDatabase()
5. Restore databas với folder chưa database:
mongo>mongorestore --host mongodb1.example.net --port 3017 --username user --password pass /opt/backup/mongodump-2013-10-24
6. Optimize server level:
- Using 64 bit instance.
- Use XFS or EXT4
- EBS in RAID. RAID 0 or 10 for data. RAID 1 for configdb
- Snapshot regularly for backup.
- Turn off atime or diratime when you mount a volume.
- GridFS for large objects. (> 16M)
- Raise file descriptor limits.
7. Optimize query performance:
- Create Indexes to Support Queries:
Should be created indexes, because scanning index is much faster than scanning a collection.
- Limit the Number of Query Results to Reduce Network Demand:
Using : limit() method.
- Use Projections to Return Only Necessary Data
Only return fields which you need for better performance.
- Use $hint to Select a Particular Index:
Use $hint for to support performance testing, or on some queries where you must select a field or field included in several indexes.
- Use the Increment Operator to Perform Operations Server-Side:
Use $inc operator to support performance testing, or on some queries where you must select a field or field included in several indexes.
Nhận xét
Đăng nhận xét