Problem phenomenon:
Throws an exception when MongoDB performs a bulk query operation Exception 2: $in needs an array.
Problem solving:
Thanks to the great Google and StackOverflow someone has encountered this problem, the cause of the problem explained very clearly, steal a lazy, direct copy come over, as follows:
This ... is a change in MongoDB 2.6.0, no longer accepting BsonObjectIn the$inClause.This particular issue is being tracker asA PHP driver bug at https://jira.mongodb.org/browse/php-1051The MongoDB PHP Driver wouldSerializeAn PHPArrayInto BSONArray(Accepted by the$inoperator) when the PHPArrayIs:sequential numerically indexed, starting from 0This meansifYou have anArrayLike$array=Array($id 0,$id 1,$id 2,$id 3,$id 4);unset($array[0]); You actually wind up with:$array=Array(1 =$id 1, 2 =$id 2, 3 =$id 3, 4 =$id); Which does not start with index0. The MongoDB PHP driver therefore converts this to a BSONObject... leading to validation error in MongoDB asIt expected anArray. Now, since the MongoDB PHP driver does not DoParse your MongoDB query we cannot know whichArrayShould is exempted from this serialization rule.The workaround is, asmentioned above, is to ensure your PHP arrays was numerically indexed, starting from 0. The easiest to DoThat's to runarray_values($values);
My English level general, belongs to the basic ability to understand the type, a little explanation, from 2.6.0 later, MongoDB in the use of $in/xxx This form of query, no longer support Bson object, and an array, if the index is not beginning with 0, then the MongoDB of PHP The driver will turn it into a Bson object by default, causing the bulk query to fail to query.
The person who said the question also said how to solve the problem by using Array_values ($values) to generate a new array with an index starting at 0.
Solve MongoDB $in needs an array problem