Gracefully disconnecting to from mongodb atlas upon restarting via nodemon - node.js

The current application is in development phase and nodejs server is restarted everything any file changes. This lets mongoose reconnect to the MongoDB server.
I am the only one user to connect to remove MongoDB atlas by I don't know how its showing 5 connections are already opened. I don't know-how.
Is there any way to disconnect from MongoDB server before restarting of the application

I am the only one user to connect to remove MongoDB atlas by I don't know how its showing 5 connections are already opened.
There are internal connections used by MongoDB for various purposes like replica set node communications.
Is there any way to disconnect from MongoDB server before restarting of the application
There surely must be but if you are concerned for Atlas having extra connections open, at this scale (5 connections) it is really not worthwhile worrying about it.

Related

Persistent socket with mongoDB and socket.io

We are facing a problem where clients connect to the server and a socket is created and is working.
But for example if the server goes down / we upgrade the version and restart the server,
the sockets are lost until clients refresh the page.
Our clients are passive, and will not refresh the page often leaving the server disconnected for updates and notifications.
We would like to know if it is possible to store the sessions somehow like a mongo store.

Firestore not reconnecting after internet connection is lost

I have a Node.js backend which is connected to Firestore and listens for document inserts and updates. At times the internet goes down on server for few minutes but when the connections comes back, the connection to Firestore in not re-established.
I have tested the same on my local also by turning off the internet and getting the same issue.
Node version: v12.14.0
firebase-admin version: "^8.9.2"
But after restarting server things goes back to normal.

Connecting to a mongoDB with a TCP prefix on a NodeJS application

I created a NodeJS app that connects with a MongoDB and it seems to work locally.
Now, after hosting the NodeJS application on a remote machine, I am trying to connect to a mongoDB that was already created on that machine. When I print out some of the environment variables, the only one I see of relevance seems to be :
MONGODB_PORT: 'tcp://172.30.204.90:27017',
I tried connecting like I usually do with
mongoose.connect('mongodb://localhost:27017/metadata/')
and replacing it with mongoose.connect('tcp://172.30.204.90:27017/metadata') but I get an error that says my URI needs to start with 'mongodb'.
So I tried replacing it with mongoose.connect('mongodb://172.30.204.90:27017/metadata') and it no longer throws any error. But on the MongoDB side I don't see any new connections happening and my app does not start up on the machine. What should I be putting in the URI?
Your URI should indeed start with mongodb:
mongoose.connect('mongodb://username:password#host:port/database?options...');
See this page for more information: https://docs.mongodb.com/manual/reference/connection-string/
Did you try to connect to the database from cli? Or Telnet to see that connection isn't blocked.

Storing information in meteor mongodb collection from outside nodejs file

I've got a mongodb collection that gets started with Meteor that I would like to connect to and edit from a nodejs file outside of meteor. From my understanding when I start meteor, I can open another terminal and type meteor mongo and it allows me to connect to the running mongodb instance that meteor is running. But how can I connect to this from a nodejs file? And add items to a collection in a database? What sort of security/authentication do I have to go through if any? (I don't remember having to set up a username/password for the mongodb, it just starts when meteor starts)
When running meteor locally, the mongodb is running on port 3001. There's no security or authentication, you simply have to connect to 127.0.0.1 port 3001, and then access the meteor database.

How to allow node mongodb to reconnect properly?

Out app is connecting into MongoDB with MongoClient.
It doesn't use any additional options in the MONGO_URL
In Locally
When mongod get closed and re-connected, client identify that and I use the db object I got from MongoClient for further read and write operations.
With a Sever
When we host our db on different server and kill mongod and restarted, existing db object does not respond and I can't read or write from it.
I need to know, is there any options I need to add to make this fixed.

Resources