Reputation: 8582
I'm trying to delete something from my mongoDb database based on the _id and i swear anything else gets deleted except what I want. I'm using a codeigniter library this is the function:
public function delete($collection = "")
{
if(empty($collection))
{
show_error("No Mongo collection selected to delete from", 500);
}
try
{
$this->db->{$collection}->remove($this->wheres, array('fsync' => TRUE, 'justOne' => TRUE));
return(TRUE);
}
catch(MongoCursorException $e)
{
show_error("Delete of data into MongoDB failed: {$e->getMessage()}", 500);
}
}
And I'm doing this to delete
$this->mongo_db->delete('videos', $data = array('_id' => $id));
It definitely deletes but not what I want. I'm new to mongo so where should I check for errors ?
Upvotes: 1
Views: 3365
Reputation: 4640
It can be caused by many elements.
new MongoId($id_as_string)
; (It should be an MongoId)safe
option (without sync) and check what you obtain as result ("safe" query return array not a boolean)Upvotes: 1
Reputation: 96258
That function expects one argument, which is the name of the collection, you call it with two. Check the docs/source to see how you can specify the where document.
Upvotes: 0