
我用db.things.ensureIndex({firstname : 1}, {unique : true, dropDups : true})或者db.things.ensureIndex({firstname : 1}, {unique : true})建立的索引使用db.getCollection('table').getIndexes()都查询不到,请问这是为什么?
现在又报E11000错误,但是我建之前已经清空了所有索引。

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
好奇怪,你的索引肯定已经创建了。你确定你的getCollection("
这里"),这里是 things? 目测长度不像。还有如果你的mongodb是3.X的话最好使用createIndex。
对于mongodb是3.x, dropDups功能已经被废弃了,可以参考
http://api.mongodb.com/python... 看那个warning
dropDups从MongoDB3.X之后已经不支持了,因为dropDups可能导致一些不可预期的错误。
从你的错误提示看,:Null 和 1995225402出现重复,你可以进到collection检查。