我有一个集合,由于首先填充它的例程,它有许多重复项。如何重复数据删除?
e.g。
{ "_id" : ObjectId("531a5fe448757e00244096fa"), "code" : "ap", "name" : "[Almost Perfect]", "value" : "[u'*']" }
{ "_id" : ObjectId("531a731148757e17587a6e04"), "code" : "ap", "name" : "[Almost Perfect]", "value" : "[u'*']" }
{ "_id" : ObjectId("531a7bb848757e1f7c0ca702"), "code" : "ap", "name" : "[Almost Perfect]", "value" : "[u'*']" }
我希望它只是一个(不关心哪个objectID被选中)
{ "_id" : ObjectId("531a5fe448757e00244096fa"), "code" : "ap", "name" : "[Almost Perfect]", "value" : "[u'*']" }
答案 0 :(得分:1)
您应该使用索引代码字段:
db.<collection>.ensureIndex({'code' : 1}, {unique : true, dropDups : true})