7

Is it possible to query for specific objects within a nested document? Heres an example,

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!
            }
        ]
    }
}

I would like my query to say { threadId : 1, 'messages.date' : { $gt : 01/01/2012 } }, { fields : { messages : 1 } }. But it will return all of that documents messages when really all i want as a result is this,

messages = [
    {
        user = bell
        date = 01/02/2012
        content = whats up
    }
]
cnotethegr8
  • 7,342
  • 8
  • 68
  • 104

1 Answers1

12

You cannot return just the selected subdocument. You'll get all of them. So you'll have to filter on the client side.

Community
  • 1
  • 1
Thilo
  • 257,207
  • 101
  • 511
  • 656