Ayoub Benayache
Ayoub Benayache

Reputation: 1164

How to distinct populated collections with mongoose

I have 2 collections and i want to get distinct subject(chapter) in selected book

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

How to use

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

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

Upvotes: 2

Views: 255

Answers (1)

Abdelfetah Chenna
Abdelfetah Chenna

Reputation: 76

You can't use that directly with mongoDB. Use an external filter.

Upvotes: 2

Related Questions