MongoDB logic and operations

Source: Internet
Author: User

Let's look at the two examples below.

Rs1: PRIMARY> db. display. find ({$ and: [{$ where: '(1386813645-this. last_active_time> 300) '}, {status: "online"}]}). count () 0rs1: PRIMARY> db. display. find ({$ where: '( 1386813645-this. last_active_time> 300) '}, {status: "online "}). count () 0 the second is equivalent to the first, which is an implicit logic and operation. For a long time, there is only the second Medium form, which may be to be more complete. After 2.0, MongoDB introduced the first form.

Reference: http://docs.mongodb.org/manual/reference/operator/query/and/

The document also mentions another method of use, that is, when performing logic and operations on a field, it can be abbreviated as follows:

Db. inventory. update ({price: {$ ne: 1.99, $ exists: true },{ $ set: {qty: 15 }})

The qty value is updated to 15 only when the price is not equal to 1.99 and exists.

Therefore, my conclusion is that it is generally good to use implicit, which is easy to write.

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.