Mongo Functions
PHP Manual

mongo_query

(PECL mongo >= 0.8.0)

mongo_queryPerforms a basic database query

Description

resource mongo_query ( resource $connection , string $ns , array $query , int $skip , int $limit , array $sort , array $fields , array $hint )

Performs a database query, returning a database cursor that can be passed to mongo_has_next or mongo_next. It is highly suggested that users use MongoCollection's find() function instead, as it is basically a wrapper for this function that handles of the extensive parameter list for the user.

Parameters

connection

The database connection to use.

ns

The database and collection name

query

The query to execute.

skip

The number of documents to skip.

limit

The maximum number of documents to return.

sort

An array of fields and directions on which to sort.

fields

An array of the fields of each document to return.

hint

An array giving the database a query hint.

Return Values

Returns a cursor to the resulting documents.

Examples

Example #1 mongo_query() example

This example shows how to use a query to get a page of search results from the database.

<?php

$searchterm 
"pandas";

$pagenum 2;
$resultsPerPage 10;

$conn mongo_connect("localhost"true);
if (!
$conn) {
   die(
"Could not connect.");
}
$cursor mongo_query($conn"zoo.animals", array("name" => $searchterm), ($pagenum-1)*$resultsPerPage$resultsPerPagenullnullnull);

?>

This returns results 11-20 of objects in the zoo.animals collection with the name field "panda".

See Also


Mongo Functions
PHP Manual