Could you please tell me why I can’t delete from collection records with ids that are in the list using mongodb $in, but I can delete them if I use mongodb driver directly. Here ids are _id generated in mongodb automatically.
This one works:
array_walk($ids, function(&$item, $key) { $item = new MongoId(trim($item)); });
$conditions = array('_id' => array('$in' => $ids),
);
$mongo = new Mongo();
$db = $mongo->test;
$collection = $db->mycollection;
$result = $collection->remove($conditions, array('safe' => true));
But using method remove of class Shanty_Mongo_Document doesn’t work for some reason with the same data:
class MyDocument extends Shanty_Mongo_Document
{
public static function bulkDelete($ids)
{
array_walk($ids, function(&$item, $key) { $item = new MongoId(trim($item)); });
$conditions = array('_id' => array('$in' => $ids)
);
$result = self::remove($conditions, array('safe' => true));
return $result['n'];
}
}
Thank you.
To solve this problem I commented in source code of Collection.php in method remove:
After it conditions with $in work. Maybe the future versions of library will fix it.