-
Type:
Bug
-
Resolution: Done
-
Priority:
Unknown
-
Affects Version/s: None
-
Component/s: None
-
None
The store creates a compound unique index on (namespace, key), but namespace is stored as an array. In MongoDB this makes it a multikey index - each array element gets its own index entry - so two documents whose namespaces share any path element and have the same key collide.
store.put(("users", "alice", "preferences"), "food", {...}) store.put(("users", "bob", "preferences"), "food", {...}) pymongo.errors.BulkWriteError: E11000 duplicate key error collection: assistant_demo.memories index: namespace_1_key_1 dup key: { namespace: "preferences", key: "food" }
Note namespace: "preferences" - a single string, not the array. That's the multikey entry. Alice's doc already claimed ("preferences", "food") and ("users", "food"), so Bob collides.
Solution could be to put index on denormalized namespace string (e.g. "users/bob/preferences") instead.