我正在尝试确保mongoDB中的索引并删除所有重复项,但它只是不起作用。我正在使用node.js本机mongo驱动程序模块。
var suggestions = db.collection('suggestions');
suggestions.dropIndex("lower");
suggestions.ensureIndex({lower: 1}, { unique: true, dropDups: true }, function(err, docs){
console.log( docs );
});
控制台记录:“lower_1”
文件看起来像:
{
"_id": {
"$oid": "54e9b2c2fe9a402c0e71adad"
},
"name": "Two door cinema club",
"weight": 0,
"lower": "two door cinema club",
"type": "performer"
},
{
"_id": {
"$oid": "54ccd65cb12c85540bbfe578"
},
"name": "Two door cinema club",
"weight": 0,
"lower": "two door cinema club",
"type": "performer"
}
没有错误,重复文档仍保留在集合中。我错过了什么吗?我可以读取和写入集合,所以我知道与DB的连接是可以的。