如何使用猫鼬区分填充集合

时间:2021-05-05 09:47:14

标签: node.js mongodb express mongoose

我有 2 个合集,我想在选定的书中获得不同的主题(章节)

Books={title:string, Chaps:Chapters, date:date}
Chapters= {title:string, subject:string}

如何使用

books.find(id:"5455545").populate('Chaps').distinct('Chaps.subject').exec(function (er,data){
    console.log(data)
    })

// i got this result => [] empty array 

1 个答案:

答案 0 :(得分:1)

你不能直接在 mongoDB 中使用它。使用外部过滤器。