Ralph Cranston
Ralph Cranston

Reputation: 21

Mongodb connectionString can't connect

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/

Upvotes: 0

Views: 688

Answers (1)

Ralph Cranston
Ralph Cranston

Reputation: 21

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",

Upvotes: 1

Related Questions