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

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

WBOY
WBOYOriginal
2016-10-17 09:30:221543browse

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>

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>

Query an array of length three

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

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>

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>

Query an array of length three

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

How to implement it using PHP

Statement:
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
Previous article:xls file processingNext article:xls file processing