我有一个类似于此的 mongodb 文档:
{
"id": 1,
"title": "This is the title",
"body" : "This is the body",
"comments": [
{
"email_address": "mirko.benedetti@somemail.com",
"name": "Mirko",
"surname": "Benedetti",
"language": "it",
"text": "This is a message",
"published": "Y",
"on": "2014-03-22 15:04:04"
},
{
"email_address": "marc.surname@somemail.com",
"name": "Marc",
"surname": "Surname",
"language": "it",
"text": "Another Message",
"published": "N",
"on": "2014-03-23 15:04:05"
}
]
}
我有一个这样的查询:
$this->db->collection->find(array('id' => $id, 'language' => $lang, 'comments.published' => 'Y'),
array('comments.name' => 1, 'comments.surname' => 1, 'comments.text' => 1, 'comments.on' => 1, '_id' => 0));
我的问题是运行该查询,mongodb 返回两个我不想要的评论,我只想要带有“已发布”的消息:“Y”。
例如,我尝试运行 'comments.published' => 'something' 并且未选择任何评论,这是正确的,但如果至少有一个评论将“已发布”标志设置为“Y”,则会显示两条评论.
欢迎任何帮助。