Querying nested embedded documents with Mongoose

前端 未结 2 1721
不思量自难忘°
不思量自难忘° 2021-01-06 10:04

I\'m trying to query inside an embedded document that is nested. I\'ve attempted to \'populate\' the results but that fails.

How do I get back all of the book detail

相关标签:
2条回答
  • 2021-01-06 10:27

    right now nested sub document population is not supported. i added a link to this post to the open github issue for future tracking.

    https://github.com/LearnBoost/mongoose/issues/601

    0 讨论(0)
  • 2021-01-06 10:39

    Deep population was added in Mongoose 3.6. https://github.com/LearnBoost/mongoose/issues/1377#issuecomment-15911192

    For your example, it would be something like:

    Owner.find().populate('shelves').exec(PopulateBooks);
    
    function PopulateBooks(err, owners) {
          if(err) throw err;
          // Deep population is here
          Book.populate(owners, { path: 'shelves.books' }).exec(callback);
    }
    
    0 讨论(0)
提交回复
热议问题