[英]how to select specific records from mongodb using php
I am using the following code:我正在使用以下代码:
foreach ($record as $doc)
{
$groupIds[] = $doc['groupId'];
}
$gpids = "'".implode("','",array_unique($groupIds))."'";
$collection5 = $db->chat;
$cursor = $collection5->find(array('groupId' => array('$in' => array($gpids))));
foreach($cursor as $res)
{
print_r($res);
}
but no results will come.但不会有结果。 Please help me.
请帮我。
That is because your $gpids
is a string and you end up putting one element array in the $in
query.那是因为您的
$gpids
是一个字符串,您最终将一个元素数组放入$in
查询中。 This should work:这应该有效:
$collection5->find(array('groupId' => array('$in' => array_unique($groupIds))));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.