An upsert into the "local.system.users" collection creates documents with no _id. Since there is an index on _id, this will create an index key of
{ "_id" : null}for the first upserted user document. So upserting another user document will fail with the following error.
E11000 duplicate key error index: local.system.users.$id dup key: { : null }
This happens only if local system.users is empty or there are no documents with _id set. If there is at least one document with _id set then it will work fine.
Since pymongo adds users using upserts, this will make pymongo fail when adding more than one local user
To replicate:
1- start a fresh 2.2.0 mongod server(nuke dbpath)
- mongod --dbpath /data/db --port 27017
2- mongo into server and use local db
- mongo
3- upsert a user document into system.users
- db.system.users.update(
{"user":"abdul"}
,
{"user":"abdul", "pwd":"xxxxxxxxx"}, true);
4- Note that inserted document does not have an _id
- db.system.users.find()
5- Insert another document
RESULT:
E11000 duplicate key error index: local.system.users.$id dup key: { : null }