===================================================
Install AEN connected to a remote Mongo DB instance
===================================================

To install AEN with a remote database:

#. Connect to the Mongodb instance and create the user for AEN:

    .. code-block:: none
    
      > user = { user: "<username>",
        pwd: "<super-secure-password>",
        roles: [
          { role: "dbOwner", db: "<db_name>" },
          { role: "dbOwner", db: "<db_name>_mq" }
        ]
      }
      > db.createUser(user)
      Successfully added user: { ... }

#. Before installing AEN-server export the database URL and name:

    .. code-block:: bash

      $ export MONGO_URL="mongodb://<username>:<password>@<host>:<port>/"
      $ export MONGO_DB="<database_name>"


#. Continue the installation process:  :doc:`Install the AEN server <../install-server-node>`.


Migrate from local to remote MongoDB
====================================


To configure your remote database to work with an already installed AEN server:

#. Stop the server, gateway and compute nodes:

   .. code-block:: bash

      sudo service wakari-server stop
      sudo service wakari-gateway stop
      sudo service wakari-compute stop

#. Open the ``/opt/wakari/wakari-server/etc/wakari/config.json``
   file and create the MONGO_URL key. For the value parameter, add the
   database information.

   The final file should read:

   .. code-block:: bash

      {
        "MONGO_URL": "mongodb://MONGO-USER:MONGO-PASSWORD@MONGO-URL:MONGO-PORT",
        "MONGO_DB": "MONGO-DB-NAME",
        "WAKARI_SERVER": "http://YOUR-IP",
        "USE_SES": false,
        "CDN": "http://YOUR-IP/static/",
        "ANON_USER": "anonymous"
      }

   For more information about configuration keys, see
   :doc:`use-config-files`.

#. Migrate the data from the former database into the new one.
   For more information, see the `MongoDB documentation website
   <https://docs.mongodb.com/manual/tutorial/backup-and-restore-tools/>`_.

#. After migration, restart the nodes:

   .. code-block:: bash

      sudo service wakari-server start
      sudo service wakari-gateway start
      sudo service wakari-compute start
