vue-express-mongo-boilerplate
vue-express-mongo-boilerplate copied to clipboard
Error connecting to MongoDB
When connecting to MongoDB Atlas, I consistently get this error. This doesn't happen on a local MongoDB server. Any idea what could be going wrong?
/Users/jc/Engineering/vue-express-mongo-boilerplate/node_modules/mongodb/lib/utils.js:123
process.nextTick(function() { throw err; });
^
MongoError: user is not allowed to do action [createIndex] on [<DATABASE>.$cmd]
at Function.MongoError.create (/Users/jc/Engineering/vue-express-mongo-boilerplate/node_modules/mongodb-core/lib/error.js:31:11)
at /Users/jc/Engineering/vue-express-mongo-boilerplate/node_modules/mongodb-core/lib/connection/pool.js:497:72
at authenticateStragglers (/Users/jc/Engineering/vue-express-mongo-boilerplate/node_modules/mongodb-core/lib/connection/pool.js:443:16)
at Connection.messageHandler (/Users/jc/Engineering/vue-express-mongo-boilerplate/node_modules/mongodb-core/lib/connection/pool.js:477:5)
at TLSSocket.<anonymous> (/Users/jc/Engineering/vue-express-mongo-boilerplate/node_modules/mongodb-core/lib/connection/connection.js:331:22)
at emitOne (events.js:115:13)
at TLSSocket.emit (events.js:210:7)
at addChunk (_stream_readable.js:266:12)
at readableAddChunk (_stream_readable.js:253:11)
at TLSSocket.Readable.push (_stream_readable.js:211:10)
at TLSWrap.onread (net.js:585:20)
[nodemon] app crashed - waiting for file changes before starting...
The error said, your user account has no right to create index in db.
@icebob thanks for getting back to me so fast. One problem is, despite setting my ENV vars, MONGO_URI
, MONGO_USERNAME
and MONGO_PASSWORD
, the values do not proliferate when running npm run dev
. I went in and hard coded them in order to get the above error, but I think it is still not using the actual user I hard coded in. That user account is an admin, so there shouldnt be any problem creating an index. If I am running dev and want to connect to a cloud db, shouldnt I just be able to set the proper ENV vars and go from there? I am missing something.
On the topic of your ENV variables not working properly make sure:
-
They are in the .env and spelled properly
-
You are using something like dotenv