Skip to content

Instantly share code, notes, and snippets.

@hrishi7
Created July 27, 2020 10:43
Show Gist options
  • Save hrishi7/7b1ed8276a62c2d3004254614bc24482 to your computer and use it in GitHub Desktop.
Save hrishi7/7b1ed8276a62c2d3004254614bc24482 to your computer and use it in GitHub Desktop.
exports.removeDuplicates = async (req, res) => {
let keywordlist = await Keyword.find();
/**get list */
for (let i = 0; i < keyword.length; i++) {
let singlekeyword = keywordlist[i];
/**get similar keyword without currentone */
let similarKeywords = await Keyword.find({
$and: [
{ keyword: new RegExp(singlekeyword.keyword, "i") },
{ _id: { $ne: singlekeyword._id } },
],
});
/**loop throght similarkeywords and add count,for,against */
/**calculate overall count, for, against */
/**updatesinglekeyword with
* keyword: singlekeyword.lowercase()
* count = singlekeyword.count + overall count
* for = singlekeyword.for + overall for
* against = singlekeyword.against + overall against
*
*
*
*/
/**after update loop similarKeywords and delete all items inside it */
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment