madhums / node-express-mongoose-demo

A simple demo app using node and mongodb for beginners (with docker)
https://nodejs-express-demo.fly.dev
MIT License
5.12k stars 1.38k forks source link

Error running the project on local #361

Closed sandeepperkariappdev closed 4 years ago

sandeepperkariappdev commented 4 years ago

I have cloned the project, replaced the MongoDB URI, with a new MongoAtlas URI, I try to run the project using yarn start, I see the following error, Can someone help me out ?

(node:66993) UnhandledPromiseRejectionWarning: MongoError: not authorized on admin to execute command { insert: "system.indexes", documents: [[{ns admin.sessions} {key [{expires 1}]} {name expires_1} {expireAfterSeconds 0} {unique false}]], ordered: true, writeConcern: { w: "majority" } } at Function.MongoError.create (/Users/sandeep.perkari/Documents/sampleapps/nodejs/smndjs/node_modules/connect-mongo/node_modules/mongodb-core/lib/error.js:31:11) at /Users/sandeep.perkari/Documents/sampleapps/nodejs/smndjs/node_modules/connect-mongo/node_modules/mongodb-core/lib/connection/pool.js:497:72 at authenticateStragglers (/Users/sandeep.perkari/Documents/sampleapps/nodejs/smndjs/node_modules/connect-mongo/node_modules/mongodb-core/lib/connection/pool.js:443:16) at Connection.messageHandler (/Users/sandeep.perkari/Documents/sampleapps/nodejs/smndjs/node_modules/connect-mongo/node_modules/mongodb-core/lib/connection/pool.js:477:5) at TLSSocket. (/Users/sandeep.perkari/Documents/sampleapps/nodejs/smndjs/node_modules/connect-mongo/node_modules/mongodb-core/lib/connection/connection.js:333:22) at TLSSocket.emit (events.js:210:5) at addChunk (_stream_readable.js:309:12) at readableAddChunk (_stream_readable.js:290:11) at TLSSocket.Readable.push (_stream_readable.js:224:10) at TLSWrap.onStreamRead (internal/stream_base_commons.js:182:23) (node:66993) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:66993) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

sandeepperkariappdev commented 4 years ago

here is the solution

https://stackoverflow.com/questions/49101567/mongodb-atlas-not-authorized-on-admin-to-execute-command

https://stackoverflow.com/questions/49179829/cannot-read-write-on-a-mongodb-atlas-database-using-mongoose/49181821#49181821

sandeepperkariappdev commented 4 years ago

On mongodb atlas we select nodejs driver version 2.2 or later it works