search documents that contains an array of objects with 2 or more keys on the basis of a single key

38 views
Skip to first unread message

Rahul Aggarwal

unread,
Dec 8, 2014, 12:02:34 AM12/8/14
to mongoo...@googlegroups.com
Hi all,
I want to search a document that contains an array of objects with 2 or more keys on the basis of a single key within the array of objects.
For example I have the following scema-
var empSchema = new Schema({
 name : String,
 age : Number,
 projects : [{id : Schema.Types.ObjectId, name : String}]

});
I want to search all emloyees who worked on project named "Sample Project".
Thanks in advance.

Jason Crawford

unread,
Dec 8, 2014, 12:07:42 AM12/8/14
to mongoo...@googlegroups.com
I think the query condition you want is:

{'projects.name': 'Sample Project'}

See relevant Mongo docs:


Hope that helps,
Jason

--
Blog: http://blog.jasoncrawford.org  |  Twitter: @jasoncrawford




--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs
---
You received this message because you are subscribed to the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages