Home:ALL Converter>mongoose query to get all distinct documents from mongodb collection

mongoose query to get all distinct documents from mongodb collection

Ask Time:2021-03-08T18:03:49         Author:Jipindas P

Json Formatter

how can i get all distinct documents from mongodb collection using mongoose query? when I use distinct with find query I'm getting array of distinct elements of the given field.

MyModel.find().distinct('_id', function(error, ids) {
// ids is an array of all ObjectIds
});

Author:Jipindas P,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/66527786/mongoose-query-to-get-all-distinct-documents-from-mongodb-collection
yy