Home > Backend Development > PHP Tutorial > How to execute mongodb's $in and $size queries in PHP

How to execute mongodb's $in and $size queries in PHP

WBOY
Release: 2016-10-17 09:30:22
Original
1573 people have browsed it

Suppose there is such a set

<code>{ "_id" : ObjectId("5022518d09248743250688e0"), "name" : "big fruit", "fruits" : [ "apple", "pear", "orange" ] } , 
{ "_id" : ObjectId("502251a309248743250688e1"), "name" : "good fruit", "fruits" : [ "banana", "pear", "orange" ] }  ,
{ "_id" : ObjectId("502251c109248743250688e2"), "name" : "good fruit", "fruits" : [ "banana", "apple", "tomato" ] }  </code>
Copy after login
Copy after login

Suppose there is such a set

RT How to write two sentences of code in PHP

<code>db.coll.find({_id:{$in[ ObjectId("502251a309248743250688e1"), ObjectId("502251c109248743250688e2")]}})</code>
Copy after login
Copy after login

Query an array of length three

<code>db.coll.find({fruits:{$size:0}})</code>
Copy after login
Copy after login

How to implement it using PHP

Reply content:

Suppose there is such a set

<code>{ "_id" : ObjectId("5022518d09248743250688e0"), "name" : "big fruit", "fruits" : [ "apple", "pear", "orange" ] } , 
{ "_id" : ObjectId("502251a309248743250688e1"), "name" : "good fruit", "fruits" : [ "banana", "pear", "orange" ] }  ,
{ "_id" : ObjectId("502251c109248743250688e2"), "name" : "good fruit", "fruits" : [ "banana", "apple", "tomato" ] }  </code>
Copy after login
Copy after login

Suppose there is such a set

RT How to write two sentences of code in PHP

<code>db.coll.find({_id:{$in[ ObjectId("502251a309248743250688e1"), ObjectId("502251c109248743250688e2")]}})</code>
Copy after login
Copy after login

Query an array of length three

<code>db.coll.find({fruits:{$size:0}})</code>
Copy after login
Copy after login

How to implement it using PHP

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template