Difference between revisions of "My MongoDB notes"

From Got Opinion Wiki
Jump to navigation Jump to search
m (added add MongoDB user section)
Line 45: Line 45:


[https://docs.mongodb.com/manual/core/security-users/ User documentation]
[https://docs.mongodb.com/manual/core/security-users/ User documentation]
Steps to setup first user and enable access control [https://docs.mongodb.com/manual/tutorial/enable-authentication/ resource]
create user administrator
<pre>use admin
db.createUser(
  {
    user: "myUserAdmin",
    pwd: "abc123",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
  }
)</pre>
Restart MongoDB instance with access control
Shutdown instance within mongo shell <code>db.adminCommand( { shutdown: 1 } )</code>


== Windows 10 (dev environment) ==
== Windows 10 (dev environment) ==

Revision as of 12:26, 11 August 2019

MongoDB is a general purpose, document-based, distributed database built for modern application developers and for the cloud era.

Ubuntu

install

Install and run MongoDB Community Edition on Ubuntu 18.04 LTS

The site has excellent documentation so I am simply providing overview of steps.

  1. Import the public key used by the package management system.
  2. Create a list file for MongoDB.
  3. Reload local package database.
  4. Install the MongoDB packages.

Run MongoDB Community Edition

  1. Start MongoDB with sudo service mongod start
  2. Verify that MongoDB has started successfully with sudo grep port /var/log/mongodb/mongod.log or sudo service mongod status
  3. Stop MongoDB with sudo service mongod stop
  4. Restart MongoDB with sudo service mongod restart
  5. Begin using MongoDB shell with mongo

Verify MongoDB starts on Ubuntu 18.04 start up (MongoDB Community Edition default install does not start on Ubuntu 18.04 startup)

$ sudo systemctl list-unit-files | grep mongod
mongod.service                             enabled  <--- If this value is not enabled, run below command to activate.

Configure MongoDB to start on Ubuntu 18.04 start up

$ sudo systemctl enable mongod.service
Created symlink /etc/systemd/system/multi-user.target.wants/mongod.service → /lib/systemd/system/mongod.service.

mongo shell

mongo shell manual

Running mongo at shell $ mongo

Exit mongo shell > exit

Display mongo shell help > help

add MongoDB user

User documentation

Steps to setup first user and enable access control resource

create user administrator

use admin
db.createUser(
  {
    user: "myUserAdmin",
    pwd: "abc123",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
  }
)

Restart MongoDB instance with access control

Shutdown instance within mongo shell db.adminCommand( { shutdown: 1 } )

Windows 10 (dev environment)

Download MongoDB Community Edition zip package

Extract downloaded file and rename to root directory to mongodb.

Move mongodb directory to user profile. On my Windows 10 dev machine the absolute path is C:\Users\anon\mongodb.

Create directory in same profile that will hold mongodb collections called mongodb-data. The absolute path is C:\Users\anon\mongodb-db.

To run MongoDB open shell in C:\Users\anon\mongodb\bin directory and type .\mongod.exe --dbpath=\Users\anon\mongodb-data\

MongoDB GUI

Robo 3T (formerly Robomongo) is the free lightweight GUI for MongoDB enthusiasts.

MongoDB drivers

MongoDB ecosystem drivers

MongoDB Node.js drivers

MongoDB Node.js API docs

My Ubuntu notes | My Windows 10 notes