dropDups true不起作用mongodb

编程入门 行业动态 更新时间:2024-10-25 00:25:33
本文介绍了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

本文发布于:2023-11-22 13:04:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1617524.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   dropDups   true   mongodb

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!