MongoDB, Mongoose: How to find subdocument in found document?

前端 未结 2 1686
深忆病人
深忆病人 2020-12-02 12:18

I\'m stuck on trying to get subdocument by _id in found document.

Example Schema

var User = mongoose.Schema({
        name:       String         


        
2条回答
  •  天涯浪人
    2020-12-02 13:15

    Adding to srquinn's answer, from my limited experience I thought populate was for joining documents from different collections together?

    I think here you could just do User.findOne({ name: 'foo' }, 'photos') which is shorthand for:

    const query = User.findOne({ name: 'foo' })
    query.select('photos')
    

提交回复
热议问题