How to 'skip' and 'include' subdocuments with mongoose query

Deadly 提交于 2019-12-12 03:32:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!