Mongoparseerror: Invalid Connection string Express+Mongo

Asked

Viewed 130 times

0

I’m using for the first time the express and the Mongo, it works normally locally, no authentication, but when I went to cloud, in the Umbler hosting it started to show error

Jan 07 14:05:19   }
Jan 07 14:05:19   name: 'MongoParseError'
Jan 07 14:05:19   at Module._compile (internal/modules/cjs/loader.js:1156:30) {
Jan 07 14:05:19   at Object.<anonymous> (/usr/src/app/src/config/database.js:12:10)
Jan 07 14:05:19   at Mongoose.connect (/usr/src/app/node_modules/mongoose/lib/index.js:344:20)
Jan 07 14:05:19   at Mongoose._promiseOrCallback (/usr/src/app/node_modules/mongoose/lib/index.js:1135:10)
Jan 07 14:05:19   at promiseOrCallback (/usr/src/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:30:10)
Jan 07 14:05:19   at new Promise (<anonymous>)
Jan 07 14:05:19   at /usr/src/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:5
Jan 07 14:05:19   at /usr/src/app/node_modules/mongoose/lib/index.js:345:10
Jan 07 14:05:19   at NativeConnection.Connection.openUri (/usr/src/app/node_modules/mongoose/lib/connection.js:817:19)
Jan 07 14:05:19   at new Promise (<anonymous>)
Jan 07 14:05:19   at /usr/src/app/node_modules/mongoose/lib/connection.js:820:12
Jan 07 14:05:19   at MongoClient.connect (/usr/src/app/node_modules/mongodb/lib/mongo_client.js:220:10)
Jan 07 14:05:19   at maybePromise (/usr/src/app/node_modules/mongodb/lib/utils.js:665:3)
Jan 07 14:05:19   at /usr/src/app/node_modules/mongodb/lib/mongo_client.js:224:5
Jan 07 14:05:19   at connect (/usr/src/app/node_modules/mongodb/lib/operations/connect.js:282:3)
Jan 07 14:05:19   at parseConnectionString (/usr/src/app/node_modules/mongodb/lib/core/uri_parser.js:565:21)
Jan 07 14:05:19   MongoParseError: Invalid connection string
Jan 07 14:05:19   Listen in 3333
Jan 07 14:05:18   [nodemon] starting `node src/index.js`
Jan 07 14:05:18   [nodemon] watching extensions: js,mjs,json
Jan 07 14:05:18   [nodemon] watching path(s): *.*
Jan 07 14:05:18   [nodemon] to restart at any time, enter `rs`
Jan 07 14:05:18   [nodemon] 2.0.6

My database.js

const mongoose = require('mongoose')
const url = 'mongo_todoappdb:27017'
const source = 'todoappdb'
const usr = '#########'
const pass = '########'
const db = 'todoappdb'

mongoose.connect(url, {
    authSource:source,
    user:usr,
    pass:pass,
    dbName:db ,
    useNewUrlParser: true,
    useUnifiedTopology: true
    
})
    .then(() => console.log('MongoDB Connected...'))
    .catch((err) => console.log(err))    




    module.exports = mongoose;
  • Oce is trying to access a Mongo base inside the Umbler itself?

  • That’s right, I’m using their Prod link

  • 1

    in my view your url should be 'mongodb://mongo_todoappdb:27017' instead of just mongo_todoappdb:27017

  • It worked! I did not pay attention to the link kkk thank you very much!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.