MongoDB

    How to start/stop the MongoDB server?

    Graphical tool

    The Stacks include a graphical tool to manage the servers easily. You can find the "manager-windows.exe", "manager-osx" or "manager-linux" tool in your installation directory. Using this tool, you can Start, Stop or Restart the servers and check the log files. You can click on the icon to start it.

    manager-servers.png

     

    manager-osx.png

     

     

     

     

     

     

     

     

     


    win_platform.png

    On Windows: You can also start the Manager tool from shortcuts: Start -> Program Files -> BitNami Stack -> Manager tool

    Command line tool

    If you prefer, you can use the "ctlscript.sh" utility from the command line. This script is in the installation directory.

    linux_platform.png

    On Virtual Machines and Cloud images:

    $ sudo /opt/bitnami/ctlscript.sh start

    A native installer on Linux:

    $ cd ~/application-version
    $ ./ctlscript.sh start
    

    mac_platform.png

     

    On OS X: You can start the Manager tool from the installation directory or you can use the "ctlscript.sh" utility from a Terminal.

    host:~ user$ cd /Applications/application-version
    host:~ user$ ./ctlscript.sh start

    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 --pasword 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-address = 127.0.0.1

    You can change this value with a valid IP from the same computer where it is installed. 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:

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

    with:

    #setParameter = enableLocalhostAuthBypass=0
    
    1. Remove admin credentials from your current MongoDB:
    $ mv /installdir/mongodb/data/db/admin.* /tmp
    1.  Restart the MongoDB server:
    $ /installdir/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 /installdir/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
    17500 view(s), 13 edit(s) and 8352 character(s)

    Comments

    You must login to post a comment.

    Attach file

    Attachments