[英]Why php mongo $in search won't work for ObjectId?
I'm new here. 我是新来的。 I'm trying to search multiple ObjectIds in MongoDB using '$in' under PHP.
我正在尝试在PHP下使用'$ in'在MongoDB中搜索多个ObjectId。 And it runs OK on RockMongo.
并且它在RockMongo上运行正常。 but it seems no luck in my own PHP codes.
但是我自己的PHP代码似乎没有运气。
Here is what I did. 这是我所做的。
In RockMongo 在RockMongo中
{
_id: {'$in': [ ObjectId("54c8a7446abe4688010041ae"), ObjectId("54c8a7446abe4688010041ad") ]}
}
In PHP 在PHP中
$tagsDB = self::getTagsDB();
$res = $tagsDB->find(array(
'_id' => array('$in' => $tagIds)
));
$tagsDB
is MongoClient connection and $res
gives me MongoCursor::__set_state(array( ))
$tagsDB
是MongoClient连接, $res
给了我MongoCursor::__set_state(array( ))
$tagIds
is an array of ObjectId
. $tagIds
是ObjectId
的数组。
If you could help me out, that would be great! 如果您能帮助我,那就太好了! Please let me know if I need to provide further information.
如果需要提供更多信息,请告诉我。
best, 最好,
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. $res
是MongoCursor对象,我需要使用iterator_to_array()
来显示结果值。
var_export(iterator_to_array($res));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.