"MongoDB tutorial 19th" PHP and MongoDB conditional query

Source: Internet
Author: User
Tags mongodb tutorial

Similar to the normal relational database, when the data is deleted, changed, check, you will use the query conditions, such as the Where in MySQL ...

In MongoDB, all the instructions that have been made by PHP are wrapped in arrays:

Mongocollection::update ( array $criteria , array $newobj [, array $options = Array ()])
Public Mongocursor Mongocollection::find ([ Array $query = array () [, Array $fields = Array ()]])
Public array Mongocollection::findone ([ Array $query = array () [, Array $fields = Array ()]])
Public mixed Mongocollection::remove ( array $criteria [, Array $options = Array ()])

Of the above four items, the bold part is actually for us to fill in the location of the query conditions.

A simple example:

$query = Array (' a ' = = ' Hello ');

$coll->find ($query);

Queries all records in the collection that are equal to hello.

can also be compounded to do:

$query = Array (' a ' = = ' Hello ', ' B ' =>1);

$coll->find ($query);

Queries all records in the collection that are equal to Hello and B is 1.

For query conditions such as greater than and less than:

$query = Array (' a ' = = ' Hello ', ' B ' =>array (' $gt ' =>10));

$coll->find ($query);

Query for all records in the collection that are equal to Hello and B are greater than ten .

More size ratios: $GT is greater than, $GTE is greater than or equal, $lt is less than, $lte is less than or equal, $ne is not equal

"MongoDB tutorial 19th" PHP and MongoDB conditional query

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.