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 |
|
|