MongoDB

    Quick reference card


      Cloud Servers Virtual Machines Native Installers
    Configuration file(s) /opt/bitnami/mongodb/mongodb.conf /opt/bitnami/mongodb/mongodb.conf install_dir/mongodb/mongodb.conf
    Log file(s) /opt/bitnami/mongodb/log/mongodb.log /opt/bitnami/mongodb/log/mongodb.log install_dir/mongodb/log/mongodb.log
    Data directory /opt/bitnami/mongodb/data/db /opt/bitnami/mongodb/data/db install_dir/mongodb/data/db
    UNIX socket /opt/bitnami/mongodb/tmp/mongodb-*.sock /opt/bitnami/mongodb/tmp/mongodb-*.sock install_dir/mongodb/tmp/mongodb-*.sock (Linux and Mac OS X)
    Default port 27017 27017 27017
    System user account mongodb mongodb mongodb
    Service control sudo /opt/bitnami/ctlscript.sh start|stop|restart mongodb sudo /opt/bitnami/ctlscript.sh start|stop|restart mongodb install_dir/ctlscript.sh start|stop|restart mongodb

    How to start/stop the MongoDB server?

    Cloud Images

    Each Bitnami stack includes a control script that lets you easily stop, start and restart servers.

    The script is located at /opt/bitnami/ctlscript.sh. Call it without any arguments to restart all services:

    $ sudo /opt/bitnami/ctlscript.sh start
    

    Or use it to restart a specific service only by passing the service name as argument - for example 'mysql':

    $ sudo /opt/bitnami/ctlscript.sh restart mysql
    

    Virtual Machine

    Each Bitnami stack includes a control script that lets you easily stop, start and restart servers.

    The script is located at /opt/bitnami/ctlscript.sh. Call it without any arguments to restart all services:

    $ sudo /opt/bitnami/ctlscript.sh start
    

    Or use it to restart a specific service only by passing the service name as argument - for example 'mysql':

    $ sudo /opt/bitnami/ctlscript.sh restart mysql
    

    Native Installer

    You can use either the graphical manager tool or the command-line tool to start and stop the servers.

    Graphical Tool

    Bitnami stacks include a graphical tool to manage the servers easily (native installers only). Using this tool, you can start, stop and restart the servers and check the log files.

    manager-servers.png

     

     

     

     

     

     

     

     

     

     

    On Windows:

    • Double-click the "manager-windows.exe" file in your installation directory.  
    • You can also start the Manager tool using the Start Menu path Start -> Program Files -> Bitnami Stack -> Manager.

    On Linux and Mac OS X:

    • Double-click the "manager-osx" or "manager-linux-*" tool in your installation directory. 
    Command-line Tool

    Each Bitnami stack includes a control script that lets you easily stop, start and restart servers.

    The control script is only available for Linux and Mac OS X native installers. The script is located in your installation directory and named ctlscript.sh. Call it without any arguments to restart all services.

    On Linux:
    If your installation directory is /home/USER/wordpress-4.0.1-0, call the control script with the ‘start’ argument to start all servers. For example:

    $ cd /home/USER/wordpress-4.0.1-0
    $ ./ctlscript.sh start
    

    Or use it to restart a specific service only by passing the service name as argument - for example 'mysql':

    $ cd /home/USER/wordpress-4.0.1-0
    $ ./ctlscript.sh restart mysql
    

    On Mac OS X:
    If your installation directory is /Applications/wordpress-4.0.1-0, call the control script with the ‘start’ argument to start all servers. For example:

    $ cd /Applications/wordpress-4.0.1-0
    $ ./ctlscript.sh start
    

    Or use it to restart a specific service only by passing the service name as argument - for example 'mysql':

    $ cd /Applications/wordpress-4.0.1-0
    $ ./ctlscript.sh restart mysql
    

    Tabs end

    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: 

    • A privileged account with a username of 'root'. The initial password for this account is the same you specified in the setup wizard.
      • If you are using the Virtual Appliance or the AMI, the password is "bitnami" by default.
      • If you are using BitNami Cloud Hosting, the password is the same that you set from the admin panel.

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

    For security reasons, the MongoDB database does not allow external connections by default. You only can connect from the local machine.

    MongoDB socket

    On Unix, the MongoDB clients can connect to the server using a Unix socket file. In a BitNami Stack, the default socket file is created in /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.

    How to connect to the MongoDB database?

    You can connect to the MongoDB database from the same computer where it is installed:

    1. Open the BitNami console
    2. Run the mongo client authenticating as the 'root' user against the 'admin' database:
    $ mongo admin --username root --password YOURPASSWORD

    You can also run the MongoDB client directly "/installdir/mongodb/bin/mongo". You can also manage the mongDB database from a browser. You can find more info at RockMongo.

    How to connect to the MongoDB database from a different machine?

    You can enable external connections for the MongoDB database by editing the following option in the "/opt/bitnami/mongodb/mongodb.conf":

    bind_ip = 127.0.0.1

    You can change this value with a valid IP from the same computer where it is installed. You can specify multiple IPs separating each IP with a comma (","). For example, if you want MongoDB to be remotely accessible on all network interfaces, you can change the IP to 0.0.0.0.

    Then, restart the MongoDB server and you can access the MongoDB database from any machine.

    sudo /opt/bitnami/ctlscript.sh restart mongodb

    If you are using a Virtual Appliance, it is also necessary to open the mongoDB port in the firewall

    How to create a database for a custom application?

    If you want to install an application manually, it may require the database settings during the installation. These are the basic steps to create a database for your application. You should run the following commands from the console, which you can access in the Windows shortcuts or from the Terminal on OS X and Linux.

    $ mongo admin --username root --password YOURPASSWORD
    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 change the MongoDB root password?

    By default, the database cannot be accessed from outside of the Virtual Machine or AMI but it is still recommended that you change the 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
    • The default password for the MongoDB root user in Virtual Appliances and AMIs is "bitnami".
    • The default password for the MongoDB root user in BitNami Cloud Hosting is the same as what you set in the administration panel.

    How to reset the MongoDB root password?

    You can reset the admin user by following the steps below:

    Note: For native installers, please, replace /opt/bitnami with your current installation directory.

    1. Edit the /opt/bitnami/mongodb/mongodb.conf and replace the following line:
    setParameter = enableLocalhostAuthBypass=0

    with:

    #setParameter = enableLocalhostAuthBypass=0
    
    1. Remove admin credentials from your current MongoDB:
    $ mv /opt/bitnami/mongodb/data/db/admin.* /tmp
    1.  Restart the MongoDB server:
    $ /opt/bitnami/ctlscript.sh restart mongodb
    

    Now you can create a new admin user with a new password. Run the following commands to do so:

    $ mongo
    > db = db.getSiblingDB('admin')
    admin
    > db.createUser( { user: "root", pwd: "new_password", roles: [ "readWriteAnyDatabase", "userAdminAnyDatabase", "dbAdminAnyDatabase", "clusterAdmin" ]} )

    Do not forget to revert the modification of /opt/bitnami/mongodb/mongodb.conf by replacing:

    #setParameter = enableLocalhostAuthBypass=0

    with:

    setParameter = enableLocalhostAuthBypass=0

    And restart the MongoDB server again.

    How to create a database backup?

    If you are interested in a backing up the data contained in your database, you can create a dump file using the “mongodump” tool.

    $ mongodump --authenticationDatabase admin --username root --password YOURPASSWORD -d database_name
    

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

    Alternatively, if you want to create a back of your full environment, please  see Native_Installers_Quick_Start_Guide#How_can_I_create_a_full_backup_of_a_Stack.3f.

    How to restore a database backup?

    If you need to restore data backed up using the previous command, you can restore a dump file using the “mongorestore” tool.

    $ mongorestore --authenticationDatabase admin --username root --password YOURPASSWORD path_to_database_dump_folder
    

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

    How to change the data directory?

    The data directory for MongoDB is in /installdir/mongodb/data/db folder by default. You can modify the location of this folder modifying the following files:

    /installdir/mongodb/mongodb.conf:

    ...
    dbpath=/installdir/mongodb/data/db
    ...

    Then move the "db" folder to the new location and restart the MongoDB server.

    How to debug errors?

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

    Tag page (Edit tags)
    • No tags
    Pages that link here
    Page statistics
    43349 view(s), 25 edit(s) and 10550 character(s)

    Comments

    You must login to post a comment.

    Attach file

    Attachments