3min
|
Writers
|
Updated 19 May 2020
Print

MongoDB

To start a database server using mongoDB in Strove, first, you need to create a folder where all data will be stored. You can do that by opening the terminal in your project folder and entering mkdir db. After that start your server by typing mongod --dbpath=./db. Here's an example using mongod with setting a path for database and port for it:

Document image

And that's basically all, your terminal should show you something similar to this:

Document image

Its default port for mongo is 27017 and it's folder path to /data/DB. There are more options for mongod you can use like changing data path or port, which you can check with mongod --help. Or going to MongoDB site with the documentation for mongod :

https://docs.mongodb.com/manual/reference/program/mongod/index.html

Now if you want to connect to a database that is already set up. You need to use mongo command line instead. Here's an example of using mongo command with ip address and port:

Document image

After that you should get mongo terminal for the database that looks like this:

Document image

You can check your connection to the database by typing db. you should get a response from the database. The default response is test. Example:

Document image

Just like for mongod you can type mongo --help for options to mongo command or go MongoDB site for more information on mongo here:

https://docs.mongodb.com/manual/reference/program/mongo/index.html