MongoDB Learning Note (ii) query

Source: Internet
Author: User

The simplest query is that MongoDB is an object-oriented one.

For example, the simplest query is only three data for the entire data set





First query for data with name Zhang San





The condition of the query is relatively good write arbitrary db.collection.find (query condition) for example


15


The result is this.


If you do not want to return a field, you can define the value of the returned field as a syntax such as Db.collection.find ({query Criteria},{return field})


16


We see that every time the query "_id" is returned, we can set it to 0 so that it does not return


Such as





The value in the key-value pair in the query condition needs to be constant so the query is not allowed > db.student.find ({"Name": "This.sex"})





Query criteria Symbols


$lt less than

$lte less than or equal

$GT Greater than

$gte greater than or equal

$in in

$nin not in

$or or

$mod

$nod Not Equal mode



For example, to query students younger than 20


18


Or query students who are older than 18 and less than 26


19


The query is basically like this.


Students aged 18 or 25 $in grammar


20


$or db.collection.find ({"$or": [{Condition0},{condition1}]})


$or syntax



The query condition is the smallest unit and can be as simple as it {"name": "Zhangsan"} name is Zhang San


can also be complex as it {"$or": [{"name": {"$in": ["Zhangsan", "Lisi"]}},{"age": {"$lt": +, "$GT": +}}]}

The name is Zhang San or John Doe, or the age is less than 26 or greater than 18.




It is necessary to say MONGO's date type


The new Date () returns a date Object and the date () returns a string of type strings that JavaScript is doing, if mixed. There will be problems when querying, updating, or deleting, so be careful when using the date type. In addition, the date object is comparable in size (the number of milliseconds stored in the new era to the current time (Greenwich)), and the string I first hehe

You can do a little experiment to make a difference.





Continue exploring tomorrow.


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.