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.
Related
We have SailsJS app with postgresql adapter. Requests made to server chokes at database query via models. i.e Users.find(). Database server is up and running, connection string is correct and one can connect to database using same connection string.
datastore has default adaptor set to sails-postgresql. If database adaptor is changed to mysql or default sails-disk, it works. But sails-postgresql is not
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.
I've connected to mLab using MongoClient.connect, but now I want to create a local database rather than use mLab. I've tried changing the URL to "mongodb://localhost:27017/mydb" to create a database locally as suggested, but I'm getting a failed to connect to server error. Is there anything I should install? Or am I just missing something?
First, install your mongoDB server:
https://docs.mongodb.com/manual/installation/
After that, you should be able to start your local mongodb server:
sudo service mongod start //in case of linux
Here the docs to start the mongodb server
Then, you will type mongo and the client command line will start.
And when typing use yourDatabase, mongo will create the database if
it does not exist.
Then, your server will be up, and the database created. Anyway, check the docs if you need the guides for windows or other systems.
First you need to understand how server works and mlab works. mLab is a company who provide database as a services. Means you no need to handle server hurdles, they take care server , backups , infrastructure etc. They provide mongodb server , You just need to create database on mongodb server's and use them.
Now comes to main points.
If you want use mongodb on your local system then you first need to install mongodb on your local system and then connect it.
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.
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.