We always see our advantages and disadvantages in the comparison, which is the same for mongodb. the comparison study allows us to master the basic knowledge about mongodb as soon as possible. Comparison between mongodb and mysql commands relational databases generally refer to databases and tables. we always see their advantages and disadvantages in comparison, which is the same for mongodb, compared and learned, we can learn the basic knowledge about mongodb as soon as possible.
Comparison between mongodb and mysql commands
Relational databases are generally composed of three levels: database, table, and record. Instead, apsaradb for mongodb is composed of three layers: database, collection, and document. Mongodb does not have the concept of the relationship between rows and columns for tables in relational databases, which reflects the free features of the mode.
The syntax commands are shown in the following table.
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 |