0

I am having two mongodb dbs running on different port, how can I connect and do operations to these both dbs using mongoose.

I know we have createconnection feature to connect to different dbs but there they are supposed to be on same url like http://localhost:{port1} and then we use mongoose.connect(http://localhost:{port1}) and then mongoose.createconnection(http://localhost:{port1}/db1) and mongoose.createconnection(http://localhost:{port1}/db1) to create two connections.

but my dbs are on http://localhost:{port1} and http://localhost:{port2}

how can I use mongoose to Connect two MONGO dbs on different port using mongoose in a node js app?

  • Does this answer your question? [Mongoose and multiple database in single node.js project](https://stackoverflow.com/questions/19474712/mongoose-and-multiple-database-in-single-node-js-project) – Buzz Moschetti Jan 28 '22 at 22:01
  • @BuzzMoschetti I saw this. In this again we are connecting to same machine but I am having different ports. – Rambo_with_bo Jan 28 '22 at 22:12
  • @BuzzMoschetti check this answer https://stackoverflow.com/a/19475270/6303273, you can set multiple port on connections. For example conn can be on portX and conn2 can be on portY. – Mohammad ZF Jan 29 '22 at 13:25

0 Answers0