How to use limit() function in Mongodb

This query will get all documents that contain MID = “53c6bfbc1ee2f2ed0acb1f0a”, don’t include 2 fields “Cap” and “Type” $pID = “53c6bfbc1ee2f2ed0acb1f0a”; $cursor = $collection->find(array(‘MID’=>$pID), array(“Cap”=>0, “Type”=>0)); If you wish to limit only 2 documents returned instead of 2000. You can use either 1 of these method below: $pID = “53c6bfbc1ee2f2ed0acb1f0a”; $cursor = $collection->find(array(‘MID’=>$pID), array(“Cap”=>0, “Type”=>0))->limit(2); Or $cursor = $collection->find(array(‘MID’=>$pID), array(“Cap”=>0, “Type”=>0)); $cursor->limit(2);

Continue reading »

Install MongoDB and config to work with PHP

Step 1: Go to mongodb.org to download the version that works for your OS. Don’t download to C:\Program Files\ directory because MongoDB doesn’t recognize space in the path. You may want to install under C:\ directory Step 2: Go to PECL to download the MongoDB driver for PHP version that runs on your OS (https://s3.amazonaws.com/drivers.mongodb.org/php/index.html) Step 3: Open php.ini, add some config options for mongodb as follow [mongodb] mongo.allow_empty_keys =0 mongo.allow_persistent = 1 mongo.chunk_size =262144 mongo.cmd = “$” mongo.default_host = “localhost” mongo.default_port = 27017 mongo.is_master_interval…

Continue reading »