Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

The MongoMinKey class

(PECL mongo >= 1.0.2)


MongoMinKey is a special type used by the database that evaluates to less than any other type. Thus, if a query is sorted by a given field in ascending order, any document with a MongoMinKey as its value will be returned first.

MongoMinKey has no associated fields, methods, or constants. It is merely the "smallest" thing that can be inserted into the database.

Class synopsis

MongoMinKey {

Using MongoMinKey as a value


->insert(array("task" => "lunch""do by" => new MongoMinKey));
$collection->insert(array("task" => "staff meeting""do by" => new MongoDate(strtotime("+4 days"))));

$cursor $collection->find()->sort(array("do by" => 1));


The cursor will contain the lunch document, then the staff meeting document. The lunch document will always be returned first, regardless of what else is added to the collection (unless other documents are added with MongoMinKey in the "do by" field).

PHP Manual