From charlesreid1

Revision as of 00:01, 31 January 2018 by Admin (talk | contribs) (→‎Configuring)

Setting Up

Installing

Debian/Ubuntu

MongoDB provides instructions for installing on Debian/Ubuntu. The short version: don't do apt-get install mongodb.

Here's what you do:

  • Add the mongodb aptitude repositories to your aptitude
  • Update your aptitude
  • Install a mongodb package from mongodb.org
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
sudo apt-get update
sudo apt-get install -y mongodb-org

These assume you have ubuntu xenial, see link [1] for other LTS releases.

Homebrew

Was able to install this ok with Homebrew: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/#install-mongodb-community-edition-with-homebrew

brew update
brew install mongodb

or to install the development version:

brew update
brew install mongodb --devel

Configuring

Link to documentation page on config options: https://docs.mongodb.com/manual/reference/configuration-options/

To start mongodb with a specified config file, use the --config or -f options:

mongod --config /etc/mongod.conf
mongod -f /etc/mongod.conf

Core mongodb config sections:

  • systemLog
  • net

systemLog

# default:

systemLog:
  destination: file
  path: /var/log/mongodb/mongod.log
  logAppend: true

can also set verbosity (0-5):

systemLog:
    destination: file
    path: /var/log/mongodb/mongod.log
    verbosity: 2
    logRotate: rename

If using logrotate util, set logRotate: reopen

Can further customize log behavior for specific components (access, commands, etc.)

net

net:
    port: 27017
    bindIp: 10.0.0.1
    ipv6: True

There are also several options for SSL. Those go into an ssl subsection of the net section of the config file.

Starting

To start the mongodb service, use the mongod service:

sudo service mongod start


Scripts

Repository with scripts, code, notes, etc. is here: https://charlesreid1.com:3000/data/mongodb

Config: https://docs.mongodb.com/manual/reference/configuration-options/

References

pymodm: https://pymodm.readthedocs.io/en/latest/getting-started.html

Database design patterns: https://docs.mongodb.com/manual/applications/data-models/

Cheat sheet: https://blog.codecentric.de/files/2012/12/MongoDB-CheatSheet-v1_0.pdf


Flags