0

Hi everyone i have a problem and i need to solve for my project of university. One of my teachers said i needed a replicate database but when i make a simple request Model.find() return a error message : Operation `users.find()` buffering timed out after 10000ms.

docker-compose.yml:

version: '3.1'
services:

  DB1:
    image: mongo:latest
    restart: always
    ports:
      - "21017:27017"
    env_file:
      - .env
    environment:
      MONGO_INITDB_ROOT_USERNAME: ${MONGO_ROOT_USR}
      MONGO_INITDB_ROOT_PASSWORD: ${MONGO_ROOT_PWD}
      MONGO_INITDB_DATABASE: test
    volumes:
      - dbdata6:/data/db

  DB2:
    image: mongo:latest
    restart: always
    ports:
      - "21018:27018"
    env_file:
      - .env
    environment:
      MONGO_INITDB_ROOT_USERNAME: ${MONGO_ROOT_USR}
      MONGO_INITDB_ROOT_PASSWORD: ${MONGO_ROOT_PWD}
      MONGO_INITDB_DATABASE: test
    volumes:
      - dbdata7:/data/db

code NodeJS:

const mongoose = require('mongoose');

async function Run() {


    var s = await mongoose.connect('mongodb://root:[email protected]:21017,127.0.0.1:21018/test',

        {
            authSource: "admin",
        }
    ).then(
        () => {
            console.log("Connected to MongoDB");
        },
        err => {
            console.error(err);
        }
    );

    console.log("Connected to MongoDB");
}

app.get(`/collectLastId`, async (req, res) => {
    var s = await require('../models/User.model.js').makeModel();

    var data = (await s.find({}));

    res.writeHead(200, { 'Content-Type': 'application/json' });
    res.end(s.toString());
});

I would like know how i can use Model.find() with two DB. Thanks!

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.