Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't create an admin user in MongoDB #261

Open
virshu opened this issue Sep 2, 2014 · 14 comments
Open

Can't create an admin user in MongoDB #261

virshu opened this issue Sep 2, 2014 · 14 comments

Comments

@virshu
Copy link

virshu commented Sep 2, 2014

I am following the readme instructions, and everything goes fine until I reach "Run our initialization script to initialize the database with a first admin user" step in configure server section. I am getting the following error when I run server/initDB.js:
...
Created new admin user...
{ [Error: getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' }
undefined

This is my first experience with MongoDB, so I am probably missing something obvious; however...

When I create a user from Mongo console, it asks for id, password and whether it is a read-only account. Very different from email / admin / etc. that is passed in initDB script.

I created an account manually; however, logging in through SCRUM app gives me "wrong name/password" error.

@petebacondarwin
Copy link
Contributor

Have you modified that config at https://github.com/angular-app/angular-app/blob/master/server/config.js

If so then make sure that you have provided a valid URL to MongoLab. Please be aware that MongoLab is not the same as hosting your own MongoDB.

@virshu
Copy link
Author

virshu commented Sep 3, 2014

I changed apiKey and dbName as instructed. dbUrl is https://api.mongolab.com/api/1 (no changes). I assumed - probably, incorrectly - that apiKey will direct to my instance of MongoDB (similar to Amazon's S3, for example).

You refer to "a valid URL to MongoLab". Not sure what it is (and can't find it in the instructions)... The hint window above my database says the following:
To connect using the shell:
mongo ds033760.mongolab.com:33760/angular -u -p
To connect using a driver via the standard URI (what's this?):
mongodb://:@ds033760.mongolab.com:33760/angular

None of them is https... and since the problem is in creating the very first user - I am not sure how I would use it.

Again, apologize for these seemingly trivial questions; it's a little frustrated to spend so much effort on MongoDB that is quite marginal to the topic of the book itself...

UPDATE: Once I created a user manually, I am able to connect from the shell (via "mongo" command). So, back to my original doubt - manual user has name/password/read-only flag. The user in the script has email/password/admin/first/last name. Is this discrepancy intentional?

@petebacondarwin
Copy link
Contributor

Does the application work if you leave the config file intact and use the provided MongoLab DB?

@petebacondarwin
Copy link
Contributor

By the way, the password that we are creating with initDB.js is specific to the Scrum app and nothing to do with MongoDB users, which are used to connect to the database.

@virshu
Copy link
Author

virshu commented Sep 3, 2014

  • Does the application work if you leave the config file intact and use the provided MongoLab DB?

No - it gives me "invalid login or password"

interesting... when I added trailing slash to url (that is, https://api.mongolab.com/api/1/ ) - it worked. weird, because the output on the screen is rest.post - https://api.mongolab.com/api/1//databases/angular/collections/users/ (with 2 slashes after 1). But now it works - and I can get to follow the Angular contents... which is what I bought the book for in the first place :)

Thanks again, and I love the book!

@petebacondarwin
Copy link
Contributor

Great. Sorry it took so long. Glad you are up and running

@virshu
Copy link
Author

virshu commented Sep 3, 2014

UPDATE: And just for testing, I put back URL without trailing slash, changed the user email (since it looks like it checks for duplicates - and got the same error as before. But slash back in - and created a second user!

  • By the way, the password that we are creating with initDB.js is specific to the Scrum app and nothing to do with MongoDB users, which are used to connect to the database.

Now I get it - I see collection called "users" in the database with JSON documents representing two Scrum users that I created...

@holladayinnn
Copy link

Thank you. adding the '/' at the end of 'https://api.mongolab.com/api/1' worked for me too.

@anujmca
Copy link

anujmca commented Apr 23, 2016

I am constantly getting this error "Error: Please provide a valid API key."

I have tried all the solutions mentioned here but nothing seems to be working, may I please request some help here.

@hosszubalazs
Copy link

Hey @anujmca !

Login to Mongolabs, and go to the following page:
https://mlab.com/user?username=[YOUREUSERNAME].

This is the page where you can check your API key and generate a new one. At the bottom of the page, click "Enable Data API access". I had a similar problem like you and this solved it for me. I also generated a new API key after enabling, this is probably not necessary.

Hope this helps!

@virshu
Copy link
Author

virshu commented Apr 23, 2016

@anujmca - I never got the error you got, and the solution that worked for me was to add trailing slash. Look - I don't mind you hijacking this thread two years later with completely irrelevant question, but if you were to create a separate thread for your question, you may have got more responses.
http://www.urbandictionary.com/define.php?term=Thread+Hijacking

@anujmca
Copy link

anujmca commented Apr 24, 2016

Solution by "hubaloo" worked, it was "Enable Data API access" which did the trick. Thank you.

@imustak07
Copy link

Yes, "Enable Data API access" and it will work. Otherwise it throws "Error: Please provide a valid API key."

@godzillalad
Copy link

I had this problem connecting on an Android device and found that it was the encoding of the parameters

handy function URI.parse took care of that

`
String uri = Uri.parse("https://api.mlab.com/api/1/databases/" + MLAB_DATABASE + "/collections/" + MLAB_COLLECTION)
.buildUpon()
.appendQueryParameter("q", "{"Id":" + 123+ "}")
.appendQueryParameter("apiKey", MLAB_API_KEY)
.build().toString();

URL urlToRequest = new URL(uri);
urlConnection = (HttpURLConnection) urlToRequest.openConnection();`

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

No branches or pull requests

7 participants