1

我确实有一个partialFilterExpression集合上的唯一索引,但有时会插入重复的数据。

索引创建

getCollection().createIndex(new BasicDBObject(userId, 1)
        , new BasicDBObject("name", "uidx-something-user")
                .append("partialFilterExpression", new BasicDBObject(Properties.someting, new BasicDBObject("$eq", true)))
                .append("unique", true));

getIndicies命令中的索引

{
        "v" : 1,
        "unique" : true,
        "key" : {
                "userId" : 1
        },
        "name" : "uidx-something-user",
        "ns" : "somewhere.something",
        "partialFilterExpression" : {
                "something" : {
                        "$eq" : true
                }
        }
}

重复的文件

{
        "_id" : "08a8506c-bcbc-4ed6-9972-67fd7c37b4bc",
        "userId" : "1068",
        "express" : false,
        "something" : true,
        "items" : [ ],
        "recipient" : {
                "_id" : "efbd8618-c480-4194-964e-f5a821edf695"
        }
}
{
        "_id" : "b6695c6a-f29d-4531-96ac-795f14c72547",
        "userId" : "1068",
        "express" : false,
        "something" : true,
        "items" : [ ],
        "recipient" : {
                "_id" : "4f93fe38-edb2-4cb7-a1b3-c2c51ac8ded1"
}

MongoDb 版本:3.2.7,似乎也发生在 3.2.12

旁注:在转储和恢复集合时,duplicate key error会抛出a

为什么有时可以插入重复数据以及如何避免这种情况?

更新

我创建了一个 MongoDb 问题https://jira.mongodb.org/browse/SERVER-28153

4

1 回答 1

0

已在 3.2.13、3.4.4、3.5.6 中修复 你在 mongodb jira中阅读更多内容

于 2018-06-07T18:48:38.307 回答