0

假设我有这个结构

    Account { 
       Id, 
       Name, 
       Password, 
       Details { 
                  LastSignedIn, 
                  CreatedDate
                  Address { 
                            City, 
                            Country
                          } 
               }
        }

Details子文档属于AccountAddress子文档属于Details

mongoose可以说检索特定的子文档或使用 findqueries 跳过另一个子文档吗?

就像是:

//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'})
4

0 回答 0