Я пытаюсь настроить контейнер NodeJS и MongoDB.
Это мое docker-compose.yml
:
version: '3'
services:
app:
container_name: newsarg-api
restart: always
build: .
ports:
- '80:3000'
links:
- mongo
mongo:
container_name: mongo
image: mongo
ports:
- '27017:27017'
Это мое соединение с mongodb:
mongoose.connect("mongodb://mongo:27017/newsarg-api", { useNewUrlParser: true })
.then(() => console.log("Connection Successful"))
.catch(err => console.log(err));
const connection = mongoose.connection
connection.once('open', function(){
console.log('MongoDB database connection established!')
})
И это ошибка, которую я получаю: ![enter image description here](https://i.stack.imgur.com/eJUxX.jpg)
Из того, что я могу сказать, именно так должно выглядеть соединение с MongoDB.
Я также попытался изменить подключение к производственному соединению, которое работает, и я все еще получаю ту же ошибку, поэтому я не уверен, идет ли оно глубже, чем соединение.
Редактировать: это это точная ошибка, которую я получаю:
newsarg-api | > backend@1.0.0 start /usr/src/app
newsarg-api | > node app.js
newsarg-api |
newsarg-api | Server is running on Port: 3000
newsarg-api | (node:19) UnhandledPromiseRejectionWarning: MongoParseError: Invalid connection string
newsarg-api | at parseConnectionString (/usr/src/app/node_modules/mongodb/lib/core/uri_parser.js:507:21)
newsarg-api | at connect (/usr/src/app/node_modules/mongodb/lib/operations/connect.js:266:3)
newsarg-api | at ConnectOperation.execute (/usr/src/app/node_modules/mongodb/lib/operations/connect.js:191:5)
newsarg-api | at executeOperation (/usr/src/app/node_modules/mongodb/lib/operations/execute_operation.js:83:26)
newsarg-api | at MongoClient.connect (/usr/src/app/node_modules/mongodb/lib/mongo_client.js:216:10)
newsarg-api | at Promise (/usr/src/app/node_modules/mongoose/lib/connection.js:632:12)
newsarg-api | at new Promise (<anonymous>)
newsarg-api | at NativeConnection.Connection.openUri (/usr/src/app/node_modules/mongoose/lib/connection.js:629:19)
newsarg-api | at Mongoose.connect (/usr/src/app/node_modules/mongoose/lib/index.js:328:15)
newsarg-api | at Object.<anonymous> (/usr/src/app/app.js:40:10)
newsarg-api | at Module._compile (internal/modules/cjs/loader.js:778:30)
newsarg-api | at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
newsarg-api | at Module.load (internal/modules/cjs/loader.js:653:32)
newsarg-api | at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
newsarg-api | at Function.Module._load (internal/modules/cjs/loader.js:585:3)
newsarg-api | at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
newsarg-api | (node:19) 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: 3)
newsarg-api | (node:19) [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.