Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Users are not being created with a userId #314

Closed
spaceraccoon opened this issue Feb 4, 2018 · 3 comments
Closed

Users are not being created with a userId #314

spaceraccoon opened this issue Feb 4, 2018 · 3 comments
Assignees
Labels

Comments

@spaceraccoon
Copy link
Collaborator

spaceraccoon commented Feb 4, 2018

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
Copy link
Member

duhaime commented Feb 4, 2018

@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
Copy link
Member

duhaime commented Feb 4, 2018

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
Copy link
Collaborator Author

spaceraccoon commented Feb 4, 2018 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants