| MySQL |
MongoDB |
Description |
| Mysqld |
Mongod |
Server Daemon |
| Mysql |
Mongo |
Client Tools |
| Mysqldump |
Mongodump |
Logical backup tools |
| Mysql |
Mongorestore |
Logical recovery tool |
| |
Db. repairDatabase () |
Restore database |
| Mysqldump |
Mongoexport |
Data export tool |
| Source |
Export Import |
Data import tool |
| Grant * privileges on *. *... |
Db. addUser () Db. auth () |
Create a user and grant permissions |
| Show databases |
Show dbs |
Show Library List |
| Show tables |
Show collections |
Display Table list |
| Show slave status |
Rs. status |
Query master/slave status |
| Create table users (a int, B int) |
Db. createCollection ("mycoll", {capped: true, Size: 100000}) and implicitly create a table. |
Create a table |
| Create INDEX idxname ON users (name) |
Db. users. ensureIndex ({name: 1 }) |
Create an index |
| Create INDEX idxname ON users (name, ts DESC) |
Db. users. ensureIndex ({name: 1, ts:-1 }) |
Create an index |
| Insert into users values (1, 1) |
Db. users. insert ({a: 1, B: 1 }) |
Insert record |
| Select a, B from users |
Db. users. find ({}, {a: 1, B: 1 }) |
Query a table |
| Select * from users |
Db. users. find () |
Query a table |
| Select * from users where age = 33 |
Db. users. find ({age: 33 }) |
Conditional query |
| Select a, B from users where age = 33 |
Db. users. find ({age: 33}, {a: 1, B: 1 }) |
Conditional query |
| Select * from users where age <33 |
Db. users. find ({'age': {$ lt: 33 }}) |
Conditional query |
| Select * from users where age> 33 and age <= 40 |
Db. users. find ({'age': {$ gt: 33, $ lte: 40 }}) |
Conditional query |
| Select * from users where a = 1 and B = 'Q' |
Db. users. find ({a: 1, B: 'q '}) |
Conditional query |
| Select * from users where a = 1 or B = 2 |
Db. users. find ({$ or: [{a: 1 },{ B: 2}]}) |
Conditional query |
| Select * from users limit 1 |
Db. users. findOne () |
Conditional query |
| Select * from users where name like "% Joe %" |
Db. users. find ({name:/Joe /}) |
Fuzzy search |
| Select * from users where name like "Joe %" |
Db. users. find ({name:/^ Joe /}) |
Fuzzy search |
| Select count (1) from users |
Db. users. count () |
Obtain the number of table records |
| Select count (1) from users where age> 30 |
Db. users. find ({age: {'$ gt': 30}). count () |
Obtain the number of table records |
| Select DISTINCT last_name from users |
Db. users. distinct ('last _ name ') |
Remove duplicate values |
| Select * from users order by name |
Db. users. find (). sort ({name:-1 }) |
Sort |
| Select * from users order by name DESC |
Db. users. find (). sort ({name:-1 }) |
Sort |
| EXPLAIN select * from users where z = 3 |
Db. users. find ({z: 3}). explain () |
Obtain the storage path |
| Update users set a = 1 where B = 'Q' |
Db. users. update ({B: 'q'}, {$ set: {a: 1 }}, false, true) |
Update record |
| Update users set a = a + 2 where B = 'Q' |
Db. users. update ({B: 'q'}, {$ inc: {a: 2 }}, false, true) |
Update record |
| Delete from users where z = "abc" |
Db. users. remove ({z: 'ABC '}) |
Delete record |
| |
Db. users. remove () |
Delete all records |
| Drop database if exists test; |
Use test Db. dropDatabase () |
Delete database |
| Drop table if exists test; |
Db. mytable. drop () |
Delete table/collection |
| |
Db. addUser ('test', 'test ') |
Add user ReadOnly --> false |
| |
Db. addUser ('test', 'test', true) |
Add user ReadOnly --> true |
| |
Db. addUser ("test", "test222 ") |
Change password |
| |
Db. system. users. remove ({user: "test "}) Or db. removeUser ('test ') |
Delete a user |
| |
Use admin |
Superuser |
| |
Db. auth ('test', 'test ') |
User authorization |
| |
Db. system. users. find () |
View user list |
| |
Show users |
View all users |
| |
Db. printCollectionStats () |
View the status of each collection |
| |
Db. printReplicationInfo () |
View Master-slave replication status |
| |
Show profile |
View profiling |
| |
Db. copyDatabase ('mail _ addr ', 'mail _ addr_tmp ') |
Copy database |
| |
Db. users. dataSize () |
View collection data size |
| |
Db. users. totalIndexSize () |
Query index size |