Get the App
SLTechnology News&Howtos  ›  Database  › 

What are the writing methods of MySQL commonly used SQL statements in MongoDB

Shulou Source: shulou.com Published: 2022-05-31 17:28:41 09月22日 Update

MySQL commonly used SQL statements in the MongoDB which are written, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

If you have been using MySQL for a long time and are eager to try MongoDB, this simple article can help you get into character faster.

What are the common SQL statements of MySQL written in MongoDB?

Query:

MySQL:

SELECT * FROM user

Mongo:

Db.user.find ()

MySQL:

SELECT * FROM user WHERE name = 'starlee'

Mongo:

Db.user.find ({'name':' starlee'})

Insert:

MySQL:

INSERT INOT user (`name`, `age`) values ('starlee',25)

Mongo:

Db.user.insert ({'name':' starlee', 'age': 25})

ALTER TABLE user... .

But in MongoDB, all you need is:

Db.user.insert ({'name':' starlee', 'age': 25,' email': 'starlee@starlee.com'})

Delete:

MySQL:

DELETE * FROM user

Mongo:

Db.user.remove ({})

MySQL:

DELETE FROM user WHERE age

< 30   Mongo:   db.user.remove({'age' : {$lt : 30}})   $gt : >

; $gte: > =; $lt: <; $lte: 20

Mongo:

Db.user.distinct ('name', {' age': {$lt: 20}})

MySQL:

SELECT name, sum (marks) FROM user GROUP BY name

Mongo:

Db.user.group ({

Key: {'name': true}

Cond: {'name':' foo'}

Reduce: function (obj,prev) {prev.msum + = obj.marks;}

Initial: {msum: 0}

})

MySQL:

SELECT name FROM user WHERE age < 20 Mongo: db.user.find ('this.age < 20, {name: 1}) found that many people are searching for data inserted in the MongoDB loop. The following is the method of inserting data in the MongoDB loop: for (var iCompositi)

Tags: Data help writing commonly used sentences articles loops clear eager to try one-off content fields for this novice method more faster knowledge structure industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Docker Linux Shulou Tech Info Redmi