Database Creation - HeadassHouse/loremaster-backend GitHub Wiki

Creating the MongoDB

Installing and Running the DB on Ubuntu

Instructions for basic installation can be found here in the official documentation. After these steps have been taken, proceed to making an account by running mongo to enter the cli.

Creating a User and DB

Start by issuing the following command:

$ use loremaster  // This will be the name of the db you want to create
$ db.createUser({
    user: "exampleUser",
    pwd: "password",  // You can also use passwordPrompt()
    [
      { role: "readWrite", db: "loremaster" } // This is the name of the db (can be anything)
    ]
})

Now navigate to the mongo.conf file ( located at /etc/mongo.conf ) and add the following lines:

# network interfaces
net:
  port: 27017
  bindIp: 0.0.0.0

#security:
security:
    authorization: 'enabled'

This will allow your db to be connected to remotely ( even though it's from your own machine ).

Using the CLI

To enter the CLI, use the mongo command

$ mongo

This will bring up the prompt, enter the following commands to enter the appropriate db and authenticate:

> use loremaster
switched to db loremaster
> db.auth("exampleUser", "password")
1
> // Now you can run any commands you would like!

The Environment Variables Used in the Project

MONGO_USERNAME              // Mongo Username ( Based on the above, that will be set to exampleUser )
MONGO_PASSWORD              // Mongo Password ( Based on the above, that will be set to password )
MONGO_CONNECTION_STRING     // In the format: {host}:{port}/{dbname} (localhost:27017/loremaster)