Get the App
SLTechnology News&Howtos  ›  Database  › 

What query syntax is available in MongoDB

Shulou Source: shulou.com Published: 2022-05-31 21:16:18 10月02日 Update

MongoDB which query syntax, many novices are not very clear, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

1. Inquiry

Find method

Db.collection_name.find ()

Query all the results:

Select * from users

Db.users.find ()

Specify which columns (keys) are returned:

Select name, skills from users

Db.users.find ({}, {'name': 1,' skills': 1})

Supplementary note: the first {} puts the where condition and the second {} specifies which columns are displayed and not displayed (0 means not displayed 1 means displayed)

Where condition:

1. It simply equals:

Select name, age, skills from users where name = 'hurry'

Db.users.find ({'name':' hurry'}, {'name': 1,' age': 1, 'skills': 1})

two。 Use and

Select name, age, skills from users where name = 'hurry' and age = 18

Db.users.find ({'name':' hurry', 'age': 18}, {' name': 1, 'age': 1,' skills': 1})

3. Use or

Select name, age, skills from users where name = 'hurry' or age = 18

Db.users.find ({'$or': [{'name':' hurry'}, {'age': 18}]}, {' name': 1, 'age': 1,' skills': 1})

4. = ($lt, $lte, $gt, $gte)

Select * from users where age > = 20 and age

Tags: Array query element update object condition type example field operator statement face meaning data support parameter command that is quantity regular Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Tech Info Linux Microsoft Shulou Information