插入多个logging时删除相同的数据

喜ia有像50m +巨大的行,其中一些是重复的值

如果存在完全相同的键和值,我不希望mongo驱动程序添加它们

一个示例数据

[{ num: "+905081472117", name: "sulocan" },{ num: "+905351224578", name: "ahmet" },{ num: "+905251223578", name: "ahmet" },{ num: "+905081472117", name: "differ" },{ num: "+905081472117", name: "sulocan" }] 

我不希望它只是检查数量我想它可以添加相同的数字与差异名称,但不添加相同的数字相同的名称

作为示例数据,我给我只希望它不会添加数组的最后一个值

 exports.addnumber = function(num, cb) { db.collection('numbers', function(err, collection) { collection.insert(num, {safe:true}, function(err, result) { if (err) { res({'error':'An error has occurred'}); } else { //console.log('Success: ' + JSON.stringify(result)); res(result); } }); }); } 

这是我用来插入值的数据库的代码

我是新手,刚开始使用mongodb

最好的祝福

您可以使用unique和dropDups属性在键和值上添加索引。 这将有所帮助。