Project single item from nested collection

Visto 233 veces
Saltar al primer mensaje no leído

John Zablocki

no leída,
20 jul 2010, 17:56:4520/7/10
a 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

no leída,
20 jul 2010, 17:59:3320/7/10
a 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

no leída,
21 jul 2010, 10:26:3921/7/10
a mongodb-user
Thanks Mike. So the new $slice operator in 1.5.x would address this?
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos