By suday405
I tried to connect mongodb and node server api app (Request URL https://services.suriyashopping.com/api/menu-list) in same droplet. The nodejs server app and mongodb running in single droplet and server placed in sub domain. I have mention my db connection code below and i got conncetion success while run server by “nodemon app.js”. But after then i made request from client to server, then i got some not authorized error. One more query is why DB and related collections not generated automatically while run server via Ubuntu terminal
mongoose.connect('mongodb://user:pwd@127.0.0.1:27017:27017/SURIYAShoppingDB', { useNewUrlParser: true }, (err, res) => {
if(err) {
console.log(err);
}
else {
console.log('MongoDB connection succeeded.');
}
})
{ MongoError: not authorized on SURIYAShoppingDB to execute command { find: “maincategories”, filter: { status: “true”, active_status: “true” }, projection: { __v: false, catgoryImage: false, active_status: false, status: false, createdAt: false, updatedAt: false }, returnKey: false, showRecordId: false } at Connection.<anonymous> (/var/www/services.suriyashopping.com/html/node_modules/mongodb-core/lib/connection/pool.js:443:61) at Connection.emit (events.js:198:13) at processMessage (/var/www/services.suriyashopping.com/html/node_modules/mongodb-core/lib/connection/connection.js:364:10) at Socket.<anonymous> (/var/www/services.suriyashopping.com/html/node_modules/mongodb-core/lib/connection/connection.js:533:15) at Socket.emit (events.js:198:13) at addChunk (_stream_readable.js:288:12) at readableAddChunk (_stream_readable.js:269:11) at Socket.Readable.push (_stream_readable.js:224:10) at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17) ok: 0, errmsg: ‘not authorized on SURIYAShoppingDB to execute command { find: “maincategories”, filter: { status: “true”, active_status: “true” }, projection: { __v: false, catgoryImage: false, active_status: false, status: false, createdAt: false, updatedAt: false }, returnKey: false, showRecordId: false }’, code: 13, name: ‘MongoError’, [Symbol(mongoErrorContextSymbol)]: {} }
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Accepted Answer
Hello,
It looks like that in your MongoDB connection string you’ve added the port twice. The port should be specified only once, here’s an example:
mongodb://DbUser:DbPass@localhost:27017/SURIYAShoppingDB
If this does not solve the problem for you, could you provide me with your mongo config file so I could advice you further?
Regards, Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.