2014년 12월 9일 화요일

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

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



I think the query condition you want is:

{'projects.name': 'Sample Project'}
See relevant Mongo docs:



댓글 없음:

댓글 쓰기