Thursday, August 8, 2013

MongooseJS Query select attributes of subdocument

MongooseJS Query select attributes of subdocument

Given a model foo with the following schema;
{
a: String,
b: [{c: String, d: String}]
}
Assume the values of a are unique, and assume the values of c in a given
foo document are unique. If I had values A and C of a and c respectively,
A uniquely identifies a foo document, and C uniquely identifies a foo.b
sub-document. Is it possible then, to forge a query that returns to me the
value of d?
Conceptually,
foo ----(find({a:A}))-----> foo_document
-----(find({c:C}))------>foo_subdoc-------(select(d))---->value_of_d
Enough information is given, I just don't know if Mongoose has a a
mechanism for this.

No comments:

Post a Comment