I tried the following code for selecting all the records from mongodb collection.But only last inserted record will come.
<?php
$m=new MongoClient();
$db=$m->trip;
if($_SERVER['REQUEST_METHOD']=="POST")
{
$userId=$_POST['userId'];
$param=explode(",",$userId);
$collection=$db->chat;
$record=$collection->find(array("userId"=>$userId));
if($record)
{
foreach($record as $rec)
{
$json=array("msg"=>$rec);
}
}
else
{
$json=array("msg"=>"No Records");
}
}
else
{
$json=array("msg"=>"Request Method is Not Accespted");
}
//output header
header('Content-type:application/json');
echo json_encode($json);
?>
But only one record will come please help me