Answer the question
In order to leave comments, you need to log in
How to remove duplicate fields of array type?
How to remove duplicate fields of array type? for 1 request to the database.
there is a document
{
ar:[0,1,2,1,2,3,1,2,3,1,2,3,3,1,3,1,1,3,2,1,3,2,1,2,3,1,3,2]
}
Answer the question
In order to leave comments, you need to log in
let ar = [0,1,2,1,2,3,1,2,3,1,2,3,3,1,3,1,1,3,2,1,3,2,1,2,3,1,3,2];
let result = [...new Set(ar)];
console.log(result);
function onlyUnique(value, index, self) {
return self.indexOf(value) === index;
}
var a = [0,1,2,1,2,3,1,2,3,1,2,3,3,1,3,1,1,3,2,1,3,2,1,2,3,1,3,2];
var unique = a.filter( onlyUnique );
db.collection.distinct(field, query, options):
https://docs.mongodb.com/manual/reference/method/d...
to execute this query via mongoose, you can start searching at:
https://stackoverflow .com/questions/6043847/how-do...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question