'Connect two MONGO dbs on different port using mongoose in a node js app

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?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source