php-mogodb中的数组投影



我有一个集合,其中包含以下条目:

"Name":"test",
"Description":"some desc here",
"Teams":[0:"idhash1",1:"idhash2"],
"clientId":"clienthash"

我从中返回的所有项目如下:

$filter = array('clientId' => $clientID);
$options = [];
$query = new MongoDBDriverQuery($filter, $options);
$cursor = $this->conn->executeQuery('dbname.collectionname', $query);

现在我想添加另一个关于团队价值的过滤器:

$filter = array('clientId' => $clientID,'Teams'=>'idhash1');
$options = [];
$query = new MongoDBDriverQuery($filter, $options);
$cursor = $this->conn->executeQuery('dbname.collectionname', $query);

这显然不起作用。我该如何让它发挥作用?我使用的是PHP7.0、MongoDB 4.0和扩展版本1.4.2

这会很有帮助$insert在MongoDB中使用Phphttp://php.net/manual/en/mongocollection.insert.php

我决定做的是不仅在数组中添加teamid,而且作为单独的键添加:

"Name":"test",
"Description":"some desc here",
"Teams":[0:"idhash1",1:"idhash2"],
"clientId":"clienthash",
"Team_idhash1":1,
"Team_idhash2":1

使查询它们变得非常容易,并且通过这种方式对团队进行过滤可以更好地执行。

最新更新