Я пытаюсь подключиться к пн go в docker с nodejs, работающим также в docker. Вот моя конфигурация. Что с ним не так?
docker -композит
version: '3'
networks:
velocity:
services:
mongo-main-gate:
image: mongo
volumes:
- ./mongo:/data/db
networks:
- velocity
main-gate:
build: .
environment:
- PORT=${PORT}
- PROD=${PROD}
- HOST=${HOST}
- MONGO_URI=${MONGO_URI}
- RPC_NODE_URL=${RPC_NODE_URL}
ports:
- ${EXT_PORT}:${PORT}
depends_on:
- mongo-main-gate
networks:
- velocity
.env
PORT=3000
PROD="true"
HOST=0.0.0.0
MONGO_URI="mongodb://mongo-main-gate:27017/maingate"
EXT_PORT=8080
RPC_NODE_URL="https://node.funcoin.io"
функция подключения
const mongoose = require('mongoose');
const callback = (err) => {
if (err) {
console.log(err.message);
} else {
console.log('Succesfully Connected!');
}
};
const init = () => {
mongoose.Promise = global.Promise;
console.info('INIT', process.env.MONGO_URI)
mongoose.connect(
process.env.MONGO_URI || 'mongodb://localhost:27017/maingate',
{ useCreateIndex: true, useNewUrlParser: true },
callback
);
};
module.exports = {
init,
callback,
};
Возврат контейнера Успешно Подключено!
Но при попытке добавить пользователей я получаю
main-gate_1 | {"level":50,"time":1587804410796,"pid":1,"hostname":"a1aad352ee4f","reqId":"cc655a95-45fb-4328-9e27-99283a393852","req":{"method":"GET","url":"/generate/mocks","hostname":"0.0.0.0:8080","remoteAddress":"172.24.0.1","remotePort":43686},"res":{"statusCode":500},"err":{"type":"MongoError","message":"Invalid namespace specified 'maingate\".users'","stack":"MongoError: Invalid namespace specified 'maingate\".users'\n at Connection.<anonymous> (/usr/src/app/node_modules/mongodb/lib/core/connection/pool.js:450:61)\n at Connection.emit (events.js:198:13)\n at processMessage (/usr/src/app/node_modules/mongodb/lib/core/connection/connection.js:384:10)\n at Socket.<anonymous> (/usr/src/app/node_modules/mongodb/lib/core/connection/connection.js:553:15)\n at Socket.emit (events.js:198:13)\n at addChunk (_stream_readable.js:288:12)\n at readableAddChunk (_stream_readable.js:269:11)\n at Socket.Readable.push (_stream_readable.js:224:10)\n at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)","ok":0,"errmsg":"Invalid namespace specified 'maingate\".users'","code":73,"codeName":"InvalidNamespace","name":"MongoError"},"msg":"Invalid namespace specified 'maingate\".users'","v":1}