the user knows, here the user get’s only the tested howtos that truly work and save a massive amount of time, trying out all the non-working howtos X-D

what is mongodb (written in C++, JavaScript, Python)

In 2013, 10gen changed its name to MongoDB Inc.[5]

On October 20, 2017, MongoDB became a publicly traded company, listed on NASDAQ as MDB with an IPO price of $24 per share.[6]

On November 8, 2018 with the stable release 4.0.4 the software’s license changed from AGPL 3.0 to SSPL v1.0. (wik)

Official MongoDB drivers use Apache License v2.0.

so a whole bunch and mix of licences making the whole thing a bit confusing.

how to install mongodb

if the user absolutely has to, for some reason not use mariadb (which is truly 100% Open Source GPL 2.0 licenced) then: As of today(Aug 29 2023) a binary for Debian 12 is not available yet. Although we can use Ubuntu’s repo to install MongoDB on Debian 12.

hostnamectl; # tested on 
Operating System: Debian GNU/Linux 12 (bookworm)  
          Kernel: Linux 6.1.0-13-amd64
    Architecture: x86-64

hostnamectl; # also tested on
Ubuntu 22.04.03 LTS

su - root
apt update
apt upgrade
apt install gnupg curl

# Import the GPG key for the repo:

curl -fsSL |sudo gpg  --dearmor -o /etc/apt/trusted.gpg.d/mongodb-server-7.0.gpg

# Adding the repository to the source list:

echo "deb [ arch=amd64,arm64 ] jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list

# Reload the local package database:

apt update

# Install the latest stable version of MongoDB:

apt install -y mongodb-org

# Start mongod service:

systemctl start mongod

# autostart mongod on boot:

systemctl enable mongod

# in order to move the mongodb files (e.g. on a separate xfs partition or harddisk?)
# because:

When running MongoDB in production on Linux, you should use Linux kernel version 2.6.36 or later, with either the XFS or EXT4 filesystem. If possible, use XFS as it generally performs better with MongoDB.

With the WiredTiger storage engine, use of XFS is strongly recommended to avoid performance issues that may occur when using EXT4 with WiredTiger. (src)

# mongo db 
# 1. create new dir

mkdir /srv/mongodb

# 2. stop mongodb

systemctl stop mongod

# 3. move the files

mv -rv /var/lib/mongodb/* /srv/mongodb/

# 4. chown
chown -R mongodb: /srv/mongodb

# 5. restart

systemctl start mongod

basic auth & basic commands

# connect to mongodb from command line
# create a password protected admin account
# it will ask interactively for password once
db.createUser( {user: "admin", pwd: passwordPrompt(), roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]})

# exit mongosh
su - root
vim /etc/mongod.conf 

# below the "security" add
  authorization: enabled

systemctl restart mongod

Ctrl+D # quit root mode
# now while it is STILL possible to connect without password like

# but also with password
mongosh -u admin -p --authenticationDatabase admin

# now basic commands

# show all existing databases
show dbs

# select a db
use admin

# what db is currently selected?

# to create and use a new db at the same time
use newdb

# insert new key:value data into the newly "created" db
db.myCollection.insertOne( { x: 1 } );

# sample output
  acknowledged: true,
  insertedId: ObjectId('6570e8a3593dd6f1f16dbde3')

# now the db is actually created
# if after use nothing is inserted the db will NOT be created

# show content of currently selected db
show collections

# display basic help

  Shell Help:

    use                                        Set current database
    show                                       'show databases'/'show dbs': Print a list of all available databases.
                                               'show collections'/'show tables': Print a list of all collections for current database.
                                               'show profile': Prints system.profile information.
                                               'show users': Print a list of all users for current database.
                                               'show roles': Print a list of all roles for current database.
                                               'show log ': log for current connection, if type is not set uses 'global'
                                               'show logs': Print all logs.

    exit                                       Quit the MongoDB shell with exit/exit()/.exit
    quit                                       Quit the MongoDB shell with quit/quit()
    Mongo                                      Create a new connection and return the Mongo object. Usage: new Mongo(URI, options [optional])
    connect                                    Create a new connection and return the Database object. Usage: connect(URI, username [optional], password [optional])
    it                                         result of the last line evaluated; use to further iterate
    version                                    Shell version
    load                                       Loads and runs a JavaScript file into the current shell environment
    enableTelemetry                            Enables collection of anonymous usage data to improve the mongosh CLI
    disableTelemetry                           Disables collection of anonymous usage data to improve the mongosh CLI
    passwordPrompt                             Prompts the user for a password
    sleep                                      Sleep for the specified number of milliseconds
    print                                      Prints the contents of an object to the output
    printjson                                  Alias for print()
    convertShardKeyToHashed                    Returns the hashed value for the input using the same hashing function as a hashed index.
    cls                                        Clears the screen like console.clear()
    isInteractive                              Returns whether the shell will enter or has entered interactive mode

  For more information on usage:


liked this article?

  • only together we can create a truly free world
  • plz support dwaves to keep it up & running!
  • (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
  • really really hate advertisement
  • contribute: whenever a solution was found, blog about it for others to find!
  • talk about, recommend & link to this blog and articles
  • thanks to all who contribute!