0

I have the following structure of a mongo document:

{
 "_id": ObjectId("4fba2558a0787e53320027eb"),
 "replies": {
    "0": {
      "email": ObjectId("4fb89a181b3129fe2d000000"),
      "sentDate": "2012-05-21T11: 22: 01.418Z",
      "type": "one"
    } 
    "1": {
     "email": ObjectId("4fb89a181b3129fe2d000000"),
     "sentDate": "2012-05-21T11: 22: 01.418Z",
      "type": "two"
    } 
    "2" ....
 }

}

How do I select only documents containing only specific type of replies, for example "type":"one"? Thank you!

4

2 回答 2

0

它就像这样工作,我第一次尝试在它上面做一个小组:

$cursor = $db->foo->find(
    array('replies.type' => 'one'), array('replies.sentDate')
);

也许它会帮助像我这样的人。键“0”、“1”……没有任何作用。

于 2012-05-27T08:39:29.960 回答
-1

$elemMatch在 mongo 文档中 查看我认为它会有所帮助。http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24all

你可以试试这个:

t.find({replies: {$elemMatch: { "type": "one" } } });
于 2012-05-21T16:13:12.517 回答