Answer the question
In order to leave comments, you need to log in
How to iterate over records to eliminate duplicates?
Can someone help me, something sensible does not fit into my head =(
There are half a million documents of the form
{
_id: ObjectId(),
tags: [слово, слово 2, слово 3]
href: 'ссылка на документ'
}
function getDocuments(request) {
return Wallpapers.aggregate([
{ $sort: request.sorting },
{ $match: request.query },
{ $skip: request.skip },
{ $limit: request.limit },
{
$project: {
_id: 1,
href: 1,
tags: 1
}
}
])
}
function cleanUniqueDocument(request) {
return arr = [], tags = [], Promise.all(request.map( async (e) => {
return tags.indexOf(e.tags.join(',')) < 0 && tags.push(e.tags.join(',')) || arr.push(e)
}))
.then(e => {
return arr || []
})
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question