问题
Let's say I have this structure
Account {
Id,
Name,
Password,
Details {
LastSignedIn,
CreatedDate
Address {
City,
Country
}
}
}
Details
subdocument belongs to Account
, Address
subdocument belongs to Details
With mongoose
can I say to retrieve the particular subdocument or skip the other one with findqueries?
Something like:
//will return in result 'Account' with only 'DetailsSubdocument' included
Account.findOne({name:'user'}, include: {'Account.DetailsSubdocument'})
//will return in result 'Account' with only 'AddressSubdocument' included
Account.findOne({name:'user'}, include: {'Details.AddressSubdocument'})
//will return in result 'Account' both two subdocuments included
Account.findOne({name:'user'}, include: {'Details.AddressSubdocument', 'Account.DetailsSubdocument'})
来源:https://stackoverflow.com/questions/35375243/how-to-skip-and-include-subdocuments-with-mongoose-query