Querying embedded documents

2,395 views
Skip to first unread message

Andy Morris

unread,
Feb 10, 2010, 12:28:10 AM2/10/10
to mongodb-user
In a collection of, say, blog posts with an embedded array of comment
documents structured like this:

{title: "asdf", body: "...", comments: [{body: "...", rating: 3},
{body: "...", rating: 4}]}

Is there currently a way to, or are there plans to allow, query the
collection to get only the embedded comments that match some criteria?
For example, if I wanted to get only the comments with a rating >= 4,
but did not want to get the rest of the post (the title, body, etc.
that is not part of an embedded comment document).

I know that something like find({"comments.rating": {$gte: 4}},
{comments: true}) will run, but it will give me all comments of blog
posts that have any comment with rating >= 4 and not just the comments
that match the query.

Thanks!

Eliot Horowitz

unread,
Feb 10, 2010, 12:48:38 AM2/10/10
to mongod...@googlegroups.com
Not currently, but it is planned.
See: http://jira.mongodb.org/browse/SERVER-142

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>

Andy Morris

unread,
Feb 10, 2010, 10:35:55 PM2/10/10
to mongodb-user
Virtual collections, nice. Even better than what I was asking for. :)

Thanks!

On Feb 9, 11:48 pm, Eliot Horowitz <eliothorow...@gmail.com> wrote:
> Not currently, but it is planned.
> See:http://jira.mongodb.org/browse/SERVER-142
>

Reply all
Reply to author
Forward
0 new messages