mongo_query
(PECL mongo >= 0.8.0)
mongo_query — Performs a basic database query
Descrição
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.
Parâmetros
- 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.
Valor Retornado
Returns a cursor to the resulting documents.
Exemplos
Exemplo #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, $resultsPerPage, null, null, null);
?>
This returns results 11-20 of objects in the zoo.animals collection with the name field "panda".
Veja Também
- mongo_has_next() - Checks if a cursor has any more documents to return
- mongo_next() - Fetches the next document returned by a query
mongo_query

mongo_next