0

I can connect via Mongodb COMPASS using my username and password but apparently i can't connect it to my website.

mongodb://localhost:27017/mydb works fine in connection string but not atlas/online cluster

{"connectionString":"mongodb+srv://myuser:[email protected]/mydb?retryWrites=true&w=majority"
    ,"secret":""}

Error :

Server listening on port 3000
Unhandled rejection MongoError: not authorized on admin to execute command { lis
tIndexes: "sessions", cursor: {  } }
    at Function.MongoError.create (C:\Users\user\Documents\GitHub\meanie\serv
er\node_modules\mongodb-core\lib\error.js:31:11)
    at queryCallback (C:\Users\user\Documents\GitHub\meanie\server\node_modul
es\mongodb-core\lib\cursor.js:212:36)
    at C:\Users\user\Documents\GitHub\meanie\server\node_modules\mongodb-core
\lib\connection\pool.js:469:18
    at processTicksAndRejections (internal/process/task_queues.js:79:11)

I am using MEANIE STACK BLOG

Reference : Cloud mongodb guide mongodb+srv://:@thiscluster.azure.mongodb.net/?retryWrites=true&w=majority

Other reference : https://docs.mongodb.com/manual/reference/connection-string/

4
  • Looks like you may have restricted permissions on the Atlas server? Did you create the user or did someone else? Commented Jun 23, 2020 at 9:05
  • @JoeDrumgoole I have full access with the database. i have set it up as dbadmin settings as well as readandwrite. where did I do wrong? Commented Jun 23, 2020 at 9:11
  • Are you connecting to the right database? Can you post a small standalone program that works locally and fails on atlas? Commented Jun 23, 2020 at 12:47
  • @JoeDrumgoole hello, i solved it just now, i was using an old version of node and the connectionString's mongo+srv can't be parsed/read by it. answer posted below Commented Jun 23, 2020 at 14:03

1 Answer 1

1

SOLVED

config.json / node's "connectionString" can't be parsed using mongo+srv://user:[email protected]/mydb?thisoptions

node version i'm using is 2.2 12

fixed via :

"connectionString":"mongodb://user:[email protected]:27017,test-shard-00-01-sample.azure.mongodb.net:27017,test-shard-00-02-sample.azure.mongodb.net:27017/THISDB?ssl=true&replicaSet=Test-shard-0&authSource=admin&retryWrites=true&w=majority",
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.