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?
-
1Yes. You are missing actually installing a server. The nodejs driver does not install the mongodb server. It's just a driver for connecting.Neil Lunn– Neil Lunn2017-07-05 12:12:01 +00:00Commented Jul 5, 2017 at 12:12
2 Answers
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
mongoand the client command line will start. And when typinguse 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.
Comments
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.