Home > Mobile >  Unable to connect to MongoDB server from host to VM
Unable to connect to MongoDB server from host to VM

Time:12-11

I'am trying to connect to a MongoDB server using mongoose but without much success, also the reason why my MongoDB server is in a VM is because MongoDB does not support Ubuntu 22.04 which I'm currently using.

Here's my code:

const mongoose = require('mongoose');
mongoose.set('strictQuery', true)

const uri = 'mongodb://192.168.137.66:27017/test';
const options = {
    autoIndex: false,
    maxPoolSize: 10,
    serverSelectionTimeoutMS: 5000,
    socketTimeoutMS: 45000,
    family: 4
};

main().catch(err => console.log(err));

async function main() {
    await mongoose.connect(uri, options);
}

There is a communication established between the host and the VM and the MongoDB is running as showcased in the following screenshot

CodePudding user response:

adding bindIpAll: true in the mongod.conf file fixed my problem.

  • Related