Bitnami MongoDB Installer

NOTE: Before running the commands shown on this page, you should load the Bitnami stack environment by executing the installdir/use_APPNAME script (Linux and Mac OS X) or by clicking the shortcut in the Start Menu under "Start -> Bitnami APPNAME Stack -> Application console" (Windows). Learn more.
NOTE: When running the commands shown on this page, replace the installdir placeholder with the full installation directory for your Bitnami stack.

Description

MongoDB is a scalable, high-performance, open source NoSQL database written in C++.

First steps with the Bitnami MongoDB Stack

Welcome to your new Bitnami application! Here are a few questions (and answers!) you might need when first starting with your application.

What are the system requirements?

Before you download and install your application, check that your system meets these requirements.

How do I install the Bitnami MongoDB Stack?

Windows, OS X and Linux installer
  • Download the executable file for the Bitnami MongoDB Stack from the Bitnami website.

  • Run the downloaded file:

    • On Linux, give the installer executable permissions and run the installation file in the console.
    • On other platforms, double-click the installer and follow the instructions shown.

Check the FAQ instructions on how to download and install a Bitnami Stack for more details.

The application will be installed to the following default directories:

Operating System Directory
Windows C:\Bitnami\APPNAME-VERSION
Mac OS X /Applications/APPNAME-VERSION
Linux /opt/APPNAME-VERSION (running as root user)
OS X VM
  • Download the OS X VM file for the Bitnami MongoDB Stack from the Bitnami website.
  • Begin the installation process by double-clicking the image file and dragging the WordPress OS X VM icon to the Applications folder.
  • Launch the VM by double-clicking the icon in the Applications folder.

What credentials do I need?

You need application credentials, consisting of a username and password. These credentials allow you to log in to your new Bitnami application.

What is the administrator username set for me to log in to the application for the first time?

  • For Windows, Linux and OS X installers, the username was configured by you when you first installed the application.
  • For OS X VMs, the username can be obtained by clicking the Bitnami badge at the bottom right corner of the application welcome page.

What is the administrator password?

  • For Windows, Linux and OS X installers, the password was configured by you when you first installed the application.
  • For OS X VMs, the password can be obtained by clicking the Bitnami badge at the bottom right corner of the application welcome page.

How to start or stop the services?

Linux

Bitnami native installers include a graphical tool to manage services. This tool is named manager-linux-x64.run on Linux and is located in the installation directory. To use this tool, double-click the file and then use the graphical interface to start, stop or restart services. Server log messages can be checked in the "Server Events" tab.

Management tool

The native installer also includes a command-line script to start, stop and restart applications, named ctlscript.sh. This script can be found in the installation directory and accepts the options start, stop, restart, and status. To use it, log in to the server console and execute it following the examples below:

  • Call it without any service names to start all services:

      $ sudo installdir/ctlscript.sh start
    
  • Use it to restart a specific service only by passing the service name as argument - for example, mysql, postgresql or apache:

      $ sudo installdir/ctlscript.sh restart mysql
      $ sudo installdir/ctlscript.sh restart postgresql
      $ sudo installdir/ctlscript.sh restart apache
    
  • Obtain current status of all services:

      $ installdir/ctlscript.sh status
    

The list of available services varies depending on the required components for each application.

Mac OS X

Bitnami native installers include a graphical tool to manage services. This tool is named manager-osx on Mac OS X and is located in the installation directory. To use this tool, double-click the file and then use the graphical interface to start, stop or restart services. Server log messages can be checked in the "Server Events" tab.

Management tool

The native installer also includes a command-line script to start, stop and restart applications, named ctlscript.sh. This script can be found in the installation directory and accepts the options start, stop, restart, and status. To use it, log in to the server console and execute it following the examples below:

  • Call it without any service names to start all services:

    $ sudo installdir/ctlscript.sh start
    
  • Use it to restart a specific service only by passing the service name as argument - for example, mysql or apache:

     $ sudo installdir/ctlscript.sh restart mysql
     $ sudo installdir/ctlscript.sh restart apache
    
  • Obtain current status of all services:

     $ installdir/ctlscript.sh status
    

The list of available services varies depending on the required components for each application.

NOTE: If you are using the stack manager for Mac OS X-VM, please check the following blog post to learn how to manage services from its graphical tool.

Windows

Bitnami native installers include a graphical tool to manage services. This tool is named manager-windows.exe on Windows and is located in the installation directory. To use this tool, double-click the file and then use the graphical interface to start, stop or restart services. Server log messages can be checked in the "Server Events" tab.

Management tool

The Windows native installer creates shortcuts to start and stop services created in the Start Menu, under "Programs -> Bitnami APPNAME Stack -> Bitnami Service". Servers can also be managed from the Windows "Services" control panel. Services are named using the format APPNAMESERVICENAME, where APPNAME is a placeholder for the application name and SERVICENAME is a placeholder for the service name. For example, the native installer for the Bitnami WordPress Stack installs services named wordpressApache and wordpressMySQL.

These services will be automatically started during boot. To modify this behaviour, refer to the section on disabling services on Windows.

What is the default configuration?

The MongoDB admin user for all databases is created during the Bitnami Stack installation process. The default configuration consists of:

  • The default data directory in Bitnami is located at installdir/mongodb/data.
  • A privileged account with a username of root. The root user has remote access to the database.

Check our recommendations for a production server.

MongoDB version

In order to see which MongoDB version are your machine running you can execute the following:

$ mongod --version

MongoDB configuration file

The MongoDB configuration file is located at installdir/mongodb/mongodb.conf.

The official MongoDB documentation has more details about how configure the MongoDB database.

MongoDB socket

On Unix, the MongoDB clients can connect to the server using a Unix socket file at installdir/mongodb/tmp/mongodb.sock.

Usually, when you use the MongoDB client tool included in the Stack, you will not need to specify the socket for the connection.

MongoDB port

The default port in which MongoDB listens is 27017.

MongoDB log file

The main MongoDB log file is at installdir/mongodb/log/mongodb.log.

How to secure your server?

  • Once you have created a new database and user credentials for your application, connect your applications to the MongoDB server using only that database and credentials.

  • If you don't need remote access for the database, make the server listen only on the local machine by editing the mongodb.conf file and uncommenting the line below:

     bind-address=127.0.0.1
    
  • If you don't need remote access for the database, make sure the MongoDB server port (usually 27017) is closed. Refer to the FAQ for more information on closing server ports.

  • Don't forget to change the root user password as explained in this section.

  • It is strongly recommended that you do not have empty passwords for any user accounts when using the server for any production work.

How to find the MongoDB database credentials?

How to connect to the MongoDB database?

You can connect to the MongoDB database from the same computer where it is installed. Run the mongo client authenticating as the root user against the admin database:

$ mongo admin --username root -p

You will be prompted to enter the root user password. This is the same as the application password.

How to connect to MongoDB from a different machine?

IMPORTANT: Bitnami Native Installers do not modify the firewall configuration of your computer, therefore the MongoDB ports could be open which is a significant security risk. You are strongly advised to close the MongoDB ports (refer to the FAQ for more information on this).

Once you have an active SSH tunnel or if you did not close the port for remote access, you can then connect to MongoDB using a command like the one below.

Remember to replace SOURCE-PORT with the source port number specified in the SSH tunnel configuration or 27017 if you did not close the port for remote access.

$ mongo admin --username root -p --host 127.0.0.1 --port SOURCE-PORT

How to change the MongoDB root password?

You can modify the MongoDB password using the following command at the shell prompt:

$ mongo admin --username root --password YOURPASSWORD
MongoDB shell version: 2.4.8
connecting to: 127.0.0.1:27017/admin
> db = db.getSiblingDB('admin')
admin
> db.changeUserPassword("root", "NEWPASSWORD")
> exit
NOTE: Remember that both YOURPASSWORD and NEWPASSWORD are placeholders. Replace them with your current password and with the new password you want to set.

How to reset the MongoDB root password?

You can reset the administrator password by following the steps below:

  • Edit the installdir/mongodb/mongodb.conf file and replace the following lines:

     # Turn on/off security.  Off is currently the default
     #noauth = true
     auth = true
    
     # Disable the HTTP interface (Defaults to localhost:27018).
     #nohttpinterface = true
     setParameter = enableLocalhostAuthBypass=0
    

    with:

     # Turn on/off security.  Off is currently the default
     noauth = true
     #auth = true
    
     # Disable the HTTP interface (Defaults to localhost:27018).
     #nohttpinterface = true
     #setParameter = enableLocalhostAuthBypass=0
    
  • Restart the MongoDB server:

     $ cd installdir
     $ sudo installdir/ctlscript.sh restart mongodb
    
  • Create a new administrative user with a new password. Run the following commands to do so (remember to replace NEWPASSWORD with the new one you want to set):

     $ mongo
     > db = db.getSiblingDB('admin')
     admin
     > db.changeUserPassword("root", "NEWPASSWORD")
    
  • Revert the modifications made to installdir/mongodb/mongodb.conf by replacing:

     # Turn on/off security.  Off is currently the default
     noauth = true
     #auth = true
    
     # Disable the HTTP interface (Defaults to localhost:27018).
     #nohttpinterface = true
     #setParameter = enableLocalhostAuthBypass=0
    

    with:

     # Turn on/off security. Off is currently the default
     #noauth = true
     auth = true
    
     # Disable the HTTP interface (Defaults to localhost:27018).
     #nohttpinterface = true
     setParameter = enableLocalhostAuthBypass=0
    
  • Restart the MongoDB server again:

     $ cd installdir
     $ sudo installdir/ctlscript.sh restart mongodb
    

How to create a database for a custom application?

If you want to install an application manually, it may require the database to be set up first. Use the commands below to create a database. Replace the DATABASE_NAME placeholder with the name of the database you wish to use and the PASSWORD placeholder with your MongoDB password.

$ mongo admin --username root --password PASSWORD
MongoDB shell version: 2.4.8
connecting to: 127.0.0.1:27017/admin
> db = db.getSiblingDB('DATABASE_NAME')
DATABASE_NAME

How to create a user with all privileges for a database?

To create a user with all privileges for a MongoDB database, select the database for use and then use the createUser() function, as shown below. Replace the DATABASE_NAME placeholder with the name of the database you wish to use, the PASSWORD placeholder with your MongoDB password, and the DATABASE_USER and DATABASE_PASSWORD placeholders with the correct user name and password.

$ mongo admin --username root --password PASSWORD
MongoDB shell version: 2.4.8
connecting to: 127.0.0.1:27017/admin
> db = db.getSiblingDB('DATABASE_NAME')
DATABASE_NAME
> db.createUser( { user: "DATABASE_USER", pwd: "DATABASE_PASSWORD", roles: [ "readWrite", "dbAdmin" ]} )
{
 "user" : "DATABASE_USER",
 "pwd" : "...",
 "roles" : [
  "readWrite",
  "dbAdmin"
 ],
 "_id" : ObjectId("...")
}
> exit

Some applications may require specific privileges in the database. Consult the official installation steps in the application documentation.

How to create a user with restricted privileges in an existing database?

In case you already have a database created, you can create a new user with restricted privileges. Find an example below of how to create a new user with read-write privileges only. Replace the DATABASE_NAME placeholder with the name of the database you wish to use, and the DATABASE_USER and DATABASE_PASSWORD placeholders with the correct user name and password.

$ mongo admin --username root --password PASSWORD
MongoDB shell version: 2.4.8
connecting to: 127.0.0.1:27017/admin
> db = db.getSiblingDB('DATABASE_NAME')
> db.createUser( { user: "DATABASE_USER", pwd: "DATABASE_PASSWORD", roles: [ "readWrite"]} )
{
   "user" : "DATABASE_USER",
    "pwd" : "...",
     "roles" : [
       "readWrite",
          ],
           "_id" : ObjectId("...")
}
> exit

You can log into an existing database with a non-root user account previously created for it, but you can use that account to create other user accounts only if it has sufficient privileges.

How can I run a command in the Bitnami MongoDB Stack?

Load the Bitnami Console and then run the command as usual.

How to create a database backup?

To back up the data contained in your database, create a dump file using the mongodump tool.

$ mongodump --authenticationDatabase admin --username root --password PASSWORD -d DATABASE_NAME

This operation could take some time depending on the amount of data that you have stored in the database.

How to restore a database backup?

To restore data backed up using the previous command, restore a dump file using the mongorestore tool.

$ mongorestore --authenticationDatabase admin --username root --password PASSWORD PATH_TO_BACKUP_FILE

Note that the steps previously described will only back up the data contained inside your database. There may be other files that you should take into account when performing a full backup, such as files that may have been uploaded to the application. These files are stored in the application folder itself, so copy this folder to have a backup of your uploaded files.

How to debug errors in your MongoDB database?

The main log file is created at installdir/mongodb/log/mongodb.log on the MongoDB database server host.

nativeInstaller

Bitnami Documentation