Showing posts with label mongodb. Show all posts
Showing posts with label mongodb. Show all posts

Sunday, February 13, 2011

search key in mongodb

$mat="superman";
 $dd=array('keywords'=>new MongoRegex("/^$mat*/i"));
$cursor = $collection->find($dd);

foreach ($cursor as $obj)
{
$moviename=$obj["moviename"];
}


query display the result where search term is equal to 'superman'





order by clause in mongodb

$dd=array('flag'=>0,'status'=>1);
$s=array( 'id' => -1);
$cursor = $collection->find($dd)->sort($s)->limit(10)->skip(0);

foreach ($cursor as $obj)
{
$username=$obj["username"];

}


  id => -1 means sorting  (desc)  order in mongodb


in sql --->       order by id desc limit 0,10;