I am saving “Article” in MongoDB as bellow with _id of integers.
When I want to delete the article with the _id in php, nothing happens.
The code I use is:
$result = $db->arcitle->remove(
array("_id" =>intVal(41)),
array('safe' => true)
);
I have tried both with and without using “safe” option, neither works. When I echo $result, it is bool(true).
Any suggestion is much appreciated!
{ "_id" : 41,
"when" : Date( 1333318420855 ),
"publisher" : "5",
"title" : "10 Steps To The Perfect Portfolio Website",
"raw" : "",
"preview" : "",
"thumbnail" : "",
"content" : [
"{}" ],
"tags" : null,
"votes" : 0,
"voters" : [],
"comments" : [] }
you’ve got a spelling mistake in the collection name.
Should probably be:
The safe option will not confirm something was deleted, only that there was no error. Remove will not trigger an error deleting something that doesn’t exist.
Note that you don’t need to recast an integer as an integer – and if you do need to cast input as an integer – use a cast statement: