downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

MongoCursor::__construct> <MongoCollection::validate
[edit] Last updated: Fri, 18 Sep 2009

view this page in

The MongoCursor class

Увод

Result object for database query.

The database is not actually queried until next() or hasNext() is called. Before the database is queried, commands can be strung together, as in:

<?php
$cursor = $collection->find()->limit(10);

// database has not yet been queried, so more search options can be added
$cursor = $cursor->sort(array("a" => 1));

var_dump($cursor->getNext());
// now database has been queried and more options cannot be added

// so this will throw an exception:
$cursor->skip(4);
?>

Синтаксис за класове

MongoCursor
implements Iterator {
/* Static Fields */
static boolean $slaveOkay = FALSE ;
/* Methods */
__construct ( resource $connection , string $ns [, array $query = array() [, array $fields = array() ]] )
public int count ( void )
public array current ( void )
protected void doQuery ( void )
public array explain ( void )
public array getNext ( void )
public boolean hasNext ( void )
public MongoCursor hint ( array $key_pattern )
public string key ( void )
public MongoCursor limit ( int $num )
public void next ( void )
public void reset ( void )
public void rewind ( void )
public MongoCursor skip ( int $num )
public MongoCursor slaveOkay ([ boolean $okay = true ] )
public MongoCursor sort ( array $fields )
public MongoCursor tailable ([ boolean $tail = true ] )
public boolean valid ( void )
}

Съдържание



add a note add a note User Contributed Notes MongoCursor
adrian dot zurek at netmedia dot com dot pl 24-Oct-2011 04:08
One *VERY* important note, if You do:
$cursor = $collection->find(array(), array('_id' => 0)); // ommit '_id' field in result

then:
var_dump(iterator_to_array($cursor));

will return only *ONE* document, not all!
Adil Baig @ AiDezigns 07-Sep-2011 07:28
If you want to know whether a cursor returned any results it is faster to use 'hasNext()' than 'count'

 
show source | credits | stats | sitemap | contact | advertising | mirror sites