YaleDHLab / nhba

A digital archive of New Haven's architecture
https://nhba.yale.edu
4 stars 4 forks source link

Users are not being created with a userId #314

Closed spaceraccoon closed 6 years ago

spaceraccoon commented 6 years ago

When users are created, no userId attribute is being set. This is also not present in the current user model. This causes duplicate errors. Note that userId 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 granting superadmin status via db.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 remove userId altogether.

On the live instance, it appears that userId is only set for the first 16 users, which is likely because of this issue.

duhaime commented 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?

duhaime commented 6 years ago

P.S. The userId attribute is completely unused -- the presence of that attribute on early user records is benign but feel free to remove...

spaceraccoon commented 6 years ago

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 .