Answers for "delete duplicate records mongo"

0

delete duplicate records mongo

db.test.ensureIndex({name: 1, nodes: 1}, {unique: true, dropDups: true})
Posted by: Guest on April-15-2022
0

delete duplicate records mongo

db.collection.aggregate([
{
    // only match documents that have this field
    // you can omit this stage if you don't have missing fieldX
    $match: {"fieldX": {$nin:[null]}}  
},
{
    $group: { "_id": "$fieldX", "doc" : {"$first": "$$ROOT"}}
},
{
    $replaceRoot: { "newRoot": "$doc"}
}
],
{allowDiskUse:true})
Posted by: Guest on April-15-2022

Code answers related to "delete duplicate records mongo"

Browse Popular Code Answers by Language