MongoDB + PHP Item wont remove()?

I'm not sure what I'm doing wrong, but with MongoDB and PHP i'm trying to do this:

$db->textures->remove(array("_id"=>$_GET['texture_id']),array("safe" => true))

But nothing happens. I did a print_r and it says:

Array ( [err] => [n] => 0 [ok] => 1 )

-------------Problems Reply------------

Crap, looks like since im removing a MongoID i have to do this:

$db->textures->remove(array("_id"=>new MongoId($_GET['texture_id'])),array("safe" => true));

If an ID is not supplied when the record is saved then yes, you'll need to use the MongoID object to build the correct search criteria. You can, however, define the _id to be whatever you want - a plain integer, text, timestamp, etc - that you can use to search on as with any other property.

See the following CLI output as an example - the first object has an _id that contains an ObjectId type, but the second contains a simple string. A search by the string works as normal:

>{ name: "Test Object 1"});
>{ _id: "abc123", "name" : "Test Object 2" });
> db.test.find();
{ "_id" : ObjectId("4cca41c9d86d000000006d33"), "name" : "Test Object 1" }
{ "_id" : "abc123", "name" : "Test Object 2">
db.test.find({"_id" : "abc123"});
{ "_id" : "abc123", "name" : "Test Object 2" } }

Category:php Views:0 Time:2010-10-29

Related post

Copyright (C), All Rights Reserved.

processed in 0.116 (s). 11 q(s)