Mysql |
Mongodb |
Description |
Mysqld |
Mongod |
Server daemon |
Mysql |
Mongo |
Client Tools |
Mysqldump |
Mongodump |
Logical Backup tool |
Mysql |
Mongorestore |
Logical Recovery Tool |
|
Db.repairdatabase () |
Repairing the database |
Mysqldump |
Mongoexport |
Data Export Tool |
Source |
Mongoimport |
Data Import Tool |
Grant * privileges on *. |
Db.adduser () Db.auth () |
New User and Permissions |
Show databases |
Show DBS |
Show Library List |
Show tables |
Show Collections |
Show Table List |
Show slave status |
Rs.status |
Querying master-Slave status |
Create table Users (a int, b int) |
Db.createcollection ("Mycoll", {capped:true, size:100000}) Another: The table can be created implicitly. |
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}) |
Inserting records |
Select A, B from users |
Db.users.find ({},{a:1, b:1}) |
Query table |
Select * from users |
Db.users.find () |
Query 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:, $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 the users where name like "%joe%" |
Db.users.find ({name:/joe/}) |
Fuzzy query |
SELECT * from the users where name like "joe%" |
Db.users.find ({name:/^joe/}) |
Fuzzy query |
Select COUNT (1) from users |
Db.users.count () |
Get table Record Count |
Select COUNT (1) from users where age>30 |
Db.users.find ({age: {' $GT ': $}}). Count () |
Get table Record Count |
Select DISTINCT last_name from Users |
Db.users.distinct (' last_name ') |
Remove duplicate values |
SELECT * from the 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 () |
Get 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 '}) |
Deleting records |
|
Db. Users.remove () |
Delete all the records |
Drop database IF EXISTS test; |
Use test Db.dropdatabase () |
Deleting a 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 User |
|
|