MongoDB Query Collation

Source: Internet
Author: User
Tags mongodb query

  • Query all
    Sql:select * FROM table_name
    Mongodb:db.getCollection (' Journal paper '). Find ({})

    As shown, get all the data under the journal paper Collection

  • Conditional query
    Note: Please note that the data type of the selected column
    1. Journal _title = ' Nature '
    Sql:select * FROM table_name where journal_title = ' Nature '
    Mongodb:db.getCollection (' Journal paper '). Find ({"Journal_title": "Nature"})

    2. volume<495:
    Sql:select * FROM table_name where volume< 495;
    Mongodb:db.getCollection (' Journal paper '). Find ({"Volume": { $lt:"495"}). Pretty ()

    3. Volume <= 495
    Sql:select * FROM table_name where volume<= 495;
    Mongodb:db.getCollection (' Journal paper '). Find ({"volume": { $lte : " 495 "}}). Pretty ()

    4. Volume >495
    Sql:select * FROM table_name where volume> 495;
    Mongodb:db.getCollection (' Journal paper '). Find ({"volume": { $gt : "495 "}}). Pretty ()

    5. Volume!=495
    Sql:select * FROM table_name where volume! = 495;
    Mongodb:db.getCollection (' Journal paper '). Find ({"volume": { $ne : "495"}} ). Pretty () and, or query

6. And query:
Sql:select * FROM table_name where journal_title = ' Nature ' and vulome> 495;
Mongodb:db.getCollection (' Journal paper '). Find ({"Journal_title": "Nature" Volume: { $gt : "495"}}). Pretty ()

7. or query:
Sql:select * FROM table_name where journal_title = ' Nature ' or vulome> 495;
Mongodb:db.getCollection (' Journal paper '). Find ({$or: [{"Journal_title": "Nature"} ,{ "volume": { $GT : "495"}]}). Pretty ()

8. And and or union query:
Sql:select * FROM table_name where volume>52 and Journ Al_title = ' Nature ' or journal_title = ' Meccanica ';
Mongodb:db.getCollection (' Journal paper '). Find ({"volume": {$gt: ' '}, $or: [{"Journal_title": "Nature"},{"Journal_title ":" Meccanica "}]}). Pretty ()

    • Get the number of data
      Sql:select Count (*) from table_name
      Mongodb:db.getCollection (' Journal paper '). COUNT ()

    • Group queries
      Sql:select Journal_title, COUNT (*) from table_name GROUP BY Journal_title
      Mongodb:db.getCollection (' Journal paper '). Aggregate ([{$group: {_id: "$journal _title", num_tutorial: {$sum: 1}}])


    • Sort
      Using the sort () method to sort data in MongoDB, the sort () method can specify a sorted field by parameter and use 1 and-one to specify how the sort is sorted, where 1 is in ascending order, and 1 is used for descending order

MongoDB Query Collation

Related Article

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.