I want to delete information from a document but the code runs and no error occurs.But it doesn’t delete the record.
I haave data like that
{
"id": "12345",
"info": [
{
"sno":1
"name": "XYZ",
"email": "xyz@example.com"
},
{
"sno":2
"name": "XYZ",
"email": "xyz@example.com"
}
]
}
and I want to delete data where id=12345 and info.sno=2
my php code id
<?
$m=new Mongo();
$db=$m->database;
$cond=array("id"=>'12345');
$data=array('$pull'=>array("info.sno"=>2));
//I used before this $data=array('$pull'=>array("info"=>array("sno"=>2)));
echo json_encode($data);
$db->info->update($cond,$data);
$st=$db->Command(array("getlasterror"=>1));
?>
I run mongo db command like:
db.info.update({"id":12345},{'$pull':{"info":{"sno":2}}});
Your commented out line is correct: