Closed spaceraccoon closed 6 years ago
@spaceraccoon This was caused by a legacy mongo autoincrement package, recently dropped as a dependency. This problem should be resolved on ec2, as I dropped the index on userId (and dropped all other indexes created by this package). To resolve this on your local machine, you should run in the mongo shell:
use nhba
show tables
db.TABLENAME.getIndexes()
Given an index with tablenameId, you should drop that index (e.g.):
> db.users.getIndexes()
[
{
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "nhba.users"
},
{
"v" : 2,
"unique" : true,
"key" : {
"userId" : 1
},
"name" : "userId_1",
"background" : true,
"ns" : "nhba.users"
}
]
> db.users.dropIndex('userId_1')
{ "nIndexesWas" : 2, "ok" : 1 }
>
Does this resolve your problem?
P.S. The userId attribute is completely unused -- the presence of that attribute on early user records is benign but feel free to remove...
Thank you! Yes, I actually used those same commands in a migration file. I wanted to check with you in case it was necessary for something else.
On Sun, Feb 4, 2018 at 2:23 PM, Douglas Duhaime notifications@github.com wrote:
P.S. The userId attribute is completely unused -- the presence of that attribute on early user records is benign but feel free to remove...
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/YaleDHLab/nhba/issues/314#issuecomment-362932163, or mute the thread https://github.com/notifications/unsubscribe-auth/ARj5GS60WIqUJ7Mmb96sp73Sts92ibj4ks5tRgOlgaJpZM4R4ped .
When users are created, no
userId
attribute is being set. This is also not present in the currentuser
model. This causes duplicate errors. Note thatuserId
is different from the_id
attribute, which is automatically generated by mongo. Mongo patterns generally suggest relying on_id
.As far as I can tell
userId
is currently only being used for ease of grantingsuperadmin
status viadb.users.update({'userId': 6}, {$set: {'superadmin': true}})
. However, this might cause confusion with_id
.Either we have to set up an autoincrementing
userId
attribute and set it with user creation or removeuserId
altogether.On the live instance, it appears that
userId
is only set for the first 16 users, which is likely because of this issue.