Project single item from nested collection

233 views
Skip to first unread message

John Zablocki

unread,
Jul 20, 2010, 5:56:45 PM7/20/10
to mongodb-user
I want to query a nested collection and return only a single item from
that nested collection. For example, if I have a (blog) post document
that has a comments collection and I want to retrieve a comment for a
single user without first retrieving all comments, is that possible?

Thanks.

-- jz

Michael Dirolf

unread,
Jul 20, 2010, 5:59:33 PM7/20/10
to mongod...@googlegroups.com
It's not (currently) possible to retrieve a single nested comment
based on a query (like by user), but you can do it based on index in
the array, or even return slices of the array (again, by index). There
are a couple of cases open that should make this behavior a bit more
flexible - virtual collections and support for the positional operator
in the fields to return document.

> --
> 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.
>
>

John Zablocki

unread,
Jul 21, 2010, 10:26:39 AM7/21/10
to mongodb-user
Thanks Mike. So the new $slice operator in 1.5.x would address this?
Reply all
Reply to author
Forward
0 new messages