7

是否可以在嵌套文档中查询特定对象?这是一个例子,

Collection : Threads
{
    Documents : Messages
    {
        threadId = 1
        messages = [
            {
                user = amy
                date = 01/01/2012
                content = hey
            },
            {
                user = bell
                date = 01/01/2012
                content = hey
            },
            {
                user = bell
                date = 01/02/2012
                content = whats up
            }
        ]
    },
    {
        threadId = 2
        messages = [
            {
                user = courtney
                date = 01/03/2012
                content = first!
            }
        ]
    }
}

我想我的查询说{ threadId : 1, 'messages.date' : { $gt : 01/01/2012 } }, { fields : { messages : 1 } }。但是当我真正想要的结果是这样时,它会返回所有这些文档消息,

messages = [
    {
        user = bell
        date = 01/02/2012
        content = whats up
    }
]
4

1 回答 1

11

您不能只返回选定的子文档。你会得到所有的。因此,您必须在客户端进行过滤。

于 2012-06-27T05:34:16.850 回答