Skip to content
This repository has been archived by the owner on Jun 11, 2021. It is now read-only.

Querying

tholder edited this page Oct 9, 2011 · 2 revisions

Return single document

Here's how you would return just a single document:


$user = Model_Mongo_User::one(array('username' => 'Tom', 'password' => 'mypassword'));

This is an AND based query.

$or

Pay particular attention to array nesting, it's easy to get it wrong.


$users = Model_Mongo_User::all(array('$or' => array(array('username' => 'Tom'), array('username' => 'Peter'))));

Sorting


Model_Mongo_User::all()->sort(array('forename' => 1));

See http://www.mongodb.org/display/DOCS/Sorting+and+Natural+Order for more information on sorting.

Sorting in Mongo is currently case sensitive, the suggested workaround is to store additional sort column without case. See:

https://jira.mongodb.org/browse/SERVER-90

More

See official Mongo page on Advance Queries http://www.mongodb.org/display/DOCS/Advanced+Queries

Clone this wiki locally