Command comparison between mongodb and mysql _ MySQL

Source: Internet
Author: User
Tags mysql commands
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.