dropDups true不起作用mongodb [英] dropDups true not working mongodb

查看:266
本文介绍了dropDups true不起作用mongodb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用mongoDB shell with version 3.0.2 我试图确保对集合users中的username字段的唯一性约束.

I am using mongoDB shell with version 3.0.2 I am trying to ensure uniqueness constraint over a username field in collection users.

这是我给的:

db.users.ensureIndex({"username": 1},{unique: true})

它给了我以下错误:

{
    "createdCollectionAutomatically" : false,
    "numIndexesBefore" : 1,
    "errmsg" : "exception: E11000 duplicate key error index: mybackend.users.$username_1 dup key: { : \"rahat\" }",
    "code" : 11000,
    "ok" : 0
}

然后我在命令中使用dropDups: true:

 db.users.ensureIndex({"username": 1},{unique: true, dropDups: true})

然后我也遇到相同的错误:

Then too I get the same error:

 {
    "createdCollectionAutomatically" : false,
    "numIndexesBefore" : 1,
    "errmsg" : "exception: E11000 duplicate key error index: mybackend.users.$username_1 dup key: { : \"rahat\" }",
    "code" : 11000,
    "ok" : 0
}

我还看到了此SO链接,但是在这里它已经有一个索引.我的没有.

I also saw this SO link but here it already had one index. Mine does not have one.

db.users.getIndexes()->

[
    {
        "v" : 1,
        "key" : {
            "_id" : 1
        },
        "name" : "_id_",
        "ns" : "mybackend.users"
    }
]

我在在github上找到此问题,并重新启动了mongo,但没有用.我究竟做错了什么?我想我在犯一个愚蠢的错误.请帮忙.

I looked for this issue on github and restarted the mongo but to no use. What am I doing wrong? I think I am doing a silly mistake. Please help.

推荐答案

自Mongo 3.0版以来,不再支持在索引创建时使用drop drop功能.有关3.0的信息,请参见兼容性更改页面释放.

The drop duplicates functionality on index creation is no longer supported since Mongo version 3.0. See the compatibility changes page for the 3.0 release.

这篇关于dropDups true不起作用mongodb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆