icebob / vue-express-mongo-boilerplate

:star: MEVN Full stack JS web app boilerplate with NodeJS, Express, Mongo and VueJS
http://vemapp.moleculer.services/
2.84k stars 757 forks source link

Error connecting to MongoDB #71

Open johncade opened 7 years ago

johncade commented 7 years ago

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...
icebob commented 7 years ago

The error said, your user account has no right to create index in db.

takotuesday commented 7 years ago

@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.

aturingmachine commented 6 years ago

On the topic of your ENV variables not working properly make sure: