Running MongoDB

Before we start MongoDB for the first time, we need to create a directory in which the mongod process will write the data:

  1. By default, the mongod process uses the /data/db directory. To create this folder, you can use the following command:
    mkdir -p /data/db
  1. Now we need to set permissions for the data directory:
    chmod -R 777 /data
  1. In a new terminal (or tab) you need to run the following:
    mongod
  1. If you didn't get an error, you could start the Mongo shell on the same host machine as mongod (in a new terminal or tab):
    mongo --host 127.0.0.1:127017
If you get an error like this: Error: Port number 127017 out of range parsing HostAndPort from "127.0.0.1:127017", then just run mongo without --host flag.
  1. Finally, if you want to stop MongoDB, press Ctrl + C in the terminal that mongod is running.
  2. If everything works, you should see this in your Terminal:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset