0

I'm new here. I'm trying to search multiple ObjectIds in MongoDB using '$in' under PHP. And it runs OK on RockMongo. but it seems no luck in my own PHP codes.

Here is what I did.

In RockMongo

{
_id: {'$in': [ ObjectId("54c8a7446abe4688010041ae"), ObjectId("54c8a7446abe4688010041ad") ]}
}

In PHP

$tagsDB = self::getTagsDB();
$res = $tagsDB->find(array(
    '_id' => array('$in' => $tagIds)
  ));

$tagsDB is MongoClient connection and $res gives me MongoCursor::__set_state(array( ))

$tagIds is an array of ObjectId.

If you could help me out, that would be great! Please let me know if I need to provide further information.

best,

Yoshi
  • 449
  • 4
  • 9

1 Answers1

0

Spending some time of research, try and error, and finally found the solution.

$res is MongoCursor object and I need to use iterator_to_array() to show result values.

var_export(iterator_to_array($res));
Yoshi
  • 449
  • 4
  • 9