Answer the question
In order to leave comments, you need to log in
Mongoose how to search inside an object nested in an array?
Let's say we have a collection consisting of the following type of objects:
Users = {
firstName: 'String',
lastName: 'String,
otherInfo: [
{_id: ''},
{_id: ''},
{_id: ''}
]
}
Answer the question
In order to leave comments, you need to log in
You can bind the query via .populate:
model:
User = new Schema({
firstName: 'String',
lastName: 'String,
otherInfo: [{type: Schema.ObjectId, ref: 'OtherInfoSchema'} ]
});
...
lastName: 'String,
otherInfo: [
{_id: '0', name: '', ... },
{_id: '1', name: '', ... }
]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question