略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: 设置查询条件

2024-05-15

设置查询条件

我们可以建立一个查询,然后传递给 MongoCollection::find() 方法来查询集合的一个子集。 例如:我们要查询 "i" 字段等于 71 的文档,我们可以使用:

<?php
$connection 
= new MongoClient();
$collection $connection->database->collectionName;

$query = array( 'i' => 71 );
$cursor $collection->find$query );

while ( 
$cursor->hasNext() )
{
    
var_dump$cursor->getNext() );
}
?>

以上例程会输出:

array(2) {
  ["_id"]=>
  object(MongoId)#6 (0) {
  }
  ["i"]=>
  int(71)
  ["_ns"]=>
  "testCollection"
}
add a note add a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/mongo.tutorial.criteria.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3