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 ...

Get React Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.