Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi, I'm using mongodb to store some data and is working fine, but I don't know how to remove documents, I'm doing:
$collection = mongodb_collection("mycollection");
$collection->remove(array('_id' => $id));
Where $id would be the mongodb id, something like "4f937d5f74b25e8d4f000000".
But this is not working. Can someone please point me in the right direction?
Thanks in advance
Comments
Comment #1
lelizondo CreditAttribution: lelizondo commentedI found that something like this will work:
$collection->remove(array('_id' => new MongoId($id)), true);
Comment #2
MiSc CreditAttribution: MiSc commentedThis is not related to the Mongodb module, so I am closing this one.
Comment #3
lelizondo CreditAttribution: lelizondo commentedYes it was related to the Mongo db module because I'm using the module and I needed help.
Anyway, I already solve it and I forgot to mark it as fixed.