http://stackoverflow.com/questions/22748000/mongodb-2-6-0-rc2-and-php-1-4-5-find-id-inA simple query like this:$a = array('_id' => array( '$in' => array_values($ids) ) );var_dump($a);$cursor2 = $data->find( $a );works in mongodb 2.4.9, however, in 2.6.0-rc2 returns this:Type: MongoCursorExceptionCode: 17287Message: Can't canonicalize query: BadValue $in needs an arrayThe output from var_dump:array(1) { ["_id"]=> array(1) { ["$in"]=> array(10) { [0]=> object(MongoId)#57 (1) { ["$id"]=> string(24) "52214d60012f8aab278eacb6" } [1]=> object(MongoId)#58 (1) { ["$id"]=> string(24) "52214d60012f8aab278eaca8" } [2]=> object(MongoId)#59 (1) { ["$id"]=> string(24) "52214d60012f8aab278eaca7" } }}}I wonder if this is a Mongo or PHP related?THanks!php mongodb mongodb-phpshareimprove this questionasked Mar 30 '14 at 18:28Pavel1831112add a comment2 Answersactive oldest votesup vote9down voteThis... is a change in MongoDB 2.6.0, no longer accepting bson object in the $in clause.This particular issue is being tracker as a PHP driver bug at https://jira.mongodb.org/browse/PHP-1051The MongoDB PHP Driver will serialize an PHP Array into BSON Array (accepted by the $in operator) when the PHP array is: Sequential numerically indexed, starting from 0This means that if you have an array like:$array = array($id0, $id1, $id2, $id3, $id4);and then youunset($array[0]);You actually wind up with:$array = array(1 => $id1, 2 => $id2, 3 => $id3, 4 => $id);Which does not start with index 0. The MongoDB PHP driver therefore converts this into a BSON Object... Leading to validation error in MongoDB as it expected an array.Now, since the MongoDB PHP driver does not do parse your MongoDB query we cannot know which array should be exempted from this serialization rule.The workaround is, as mentioned above, is to ensure your PHP arrays are numerically indexed, starting from 0. The easiest way to do that is to runarray_values($values);shareimprove this answeredited Jul 31 at 9:43Kevin Yan586315answered Apr 9 '14 at 0:49bjori1,276158-1 Sorry, but check the code in question, array_values is used already. - Imran Naqvi Aug 28 '14 at 9:52This answer helped me with a problem I had using jenssegers/laravel-mongodb vendor for Laravel. I am posting an issue on their Gitgub account with a reference to this answer for support. Thanks! - rayVenues Sep 30 '14 at 12:28add a commentup vote2down voteAfter debugging it with mongo, I've noticed the following:... query: { _id: { $in: { 0: ObjectId('52214d60012f8aab278eaad1') ...but it should be... query: { _id: { $in: [ ObjectId('52214d60012f8aab278eaad1') ...So, I would suggest doing array_values($VAR) before calling $in, I'm guess Mongo 2.4.9 is more lenient to the fact that $ids can be either object or an array, make sure you use arrays in mongo 2.6 ;)shareimprove this answeranswered Apr 3 '14 at 21:35Pavel1831112nice catch with array_values - Thiago F Macedo Apr 24 '14 at 13:17-1, Sorry but please check in the code, array_values is used. - Imran Naqvi Aug 28 '14 at 9:50add a comment