MongoError: cannot do raw queries on admin in atlas

How do I fix this problem in my glitch app:

MongoError: cannot do raw queries on admin in atlas

link to my app:
glitch app

In the connection string, change /admin to the name of the database which has your data, example /test

3 Likes

Worked for me.
Thank you.

Worked for me too. Thank you so much!

Hello there,
I have the same issue, but I have already /test in my connection string so what next step to go ahead ?
link to my code: https://glitch.com/edit/#!/puzzled-floss

@GoupilJeremy I had a look, your project is using an older version of node and mongoose, you may have more luck with a newer template, although it may not matter.

This is the connect string I have in .env … the quotes are needed because of the ampersand & . If your user name or password has special characters, they would need to be uuencoded.

MONGO_URI='mongodb+srv://myuser:mypassword@cluster0-myhost.mongodb.net/test?retryWrites=true&w=majority'

1 Like

@mishavee Thank you for the help, where can i find the newer template?

My connect string in.env : DATABASE=‘mongodb+srv://username:password@cluster0-22nax.azure.mongodb.net/test?retryWrites=true&w=majority’;

@GoupilJeremy your connection string looks okay. What error are you getting?

Link to full instructions https://www.freecodecamp.org/learn/apis-and-microservices/mongodb-and-mongoose/

Some things to check in the database settings:

  • User permissions
  • Add any server to firewall whitelist

@GoupilJeremy, are you using MongoDB Atlas? If you’re using MongoDB Atlas, you also need to whitelist 0.0.0.0/0 (allow access from anywhere), only then can you use MongoDB Atlas from Glitch.

The issue seems to be with the mongodb driver version in the cloned project package.json file and the mongodb Atlas connection string.

Take a look at your package.json file and look for the mongodb version in your dependencies. If you cloned the github project, the mongodb version is probably an older version. You can update this version but I wouldn’t do that because I don’t know what effect it will have on the tests.

Better solution for this is to go into your Atlas account where you copy your connection string and select the appropriate driver version. This will give you a new connection string with all the right parameters for the mongodb driver you are using.

In short, your package.json mongodb version should match the version selected for the Atlas connection string.

Hope this helps.

1 Like

Perfect! This worked perfectly and is a great lesson for the future.