ALTERYX INSPIRE | Join us this May for for a multi-day virtual analytics + data science experience like no other! Register Now
2 Day Countdown - The Alteryx Community will be temporarily unavailable for a few hours due to scheduled maintenance starting on Thursday, April 22nd at 5pm MDT. Please plan accordingly.

Alteryx Server Knowledge Base

Definitive answers from Server experts.

How to Create a User-Managed MongoDB Instance

MattH
Alteryx
Alteryx
Created

One of the three database options when setting up the Alteryx Server is to connect into a User-Managed MongoDB instance. Why would you want to set up your own implementation of MongoDB? The main benefits are to take advantage of the features of MongoDB that are not included with our embedded instance:

  • Replication - to provide data redundancy
  • Sharding - to distribute data over multiple servers

Please note that for user managed MongoDB mongoDB direct access is enabled by default. So every node needs direct access to the servers hosting the MongoDB.

To start up your own MongoDB instance, you will first need to download the software.

For this article, I am going to mimic the setup we use for our current Alteryx Server, which is using MongoDB version 4.0.18:

http://downloads.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-4.0.18.zip
or
http://downloads.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-4.0.18-signed.msi

Unzip or Install MongoDB in the folder of your choice. I will be using C:\MongoDB\4.0\bin for my own implementation. I am also creating two new folders:

C:\MongoDB\data - for the database
C:\MongoDB\log - for log files

Open two Windows Command Prompts as an administrator. One we will use for the Mongo Service and the other for the Mongo Client, which I will refer as the Daemon and Client windows from now on.


In both windows change into your MongoDB bin directory:

cd \MongoDB\4.0\bin

Now, in the Daemon window, start up the MongoDB service:

mongod --dbpath C:\MongoDB\data
Look for the following line, it should be at the end of the start up dialog:
2017-01-31T09:02:04.472-0700 I NETWORK [initandlisten] waiting for connections on port 27017

Switch over to the Client window and connect into the newly created database:

mongo localhost:27017

Now, create the admin database. The use command allows you to switch into another database; if a database with the name you provided does not exist, MongoDB will create it for you:

use admin

Once inside the Admin database, create the default MongoDB administrator and authenticate the account:

db.createUser({user:"userAdmin", pwd:"password",roles:["root"]})

With the db.createUser() command we are creating the username we wish to use, the password for that user, and the database role for the account. For more information on the types of roles available to MongoDB, take a look at the following URL. The db.auth() command authenticates the username and password to the database, allowing that user to log in with the provided credentials.

We can now restart MongoDB to use our new authentication. First, let's exit out of the database and shut it down (keep both Command Windows open as we will still need them). In the Client window, type the following:

exit

In the Daemon window, hit Ctrl+C on your keyboard to shut down the MongoDB service. Restart the service back up with the --auth parameter to enable authentication:

mongod --dbpath C:\MongoDB\data --auth

In the Client window, let's log in to the admin database with our credentials:

mongo localhost:27017/admin -u userAdmin -p password

There are three databases we need to create: AlteryxService, AlteryxGallery, and AlteryxGallery_Lucene. We will create, add the same user account to each database, and authenticate the account:

use AlteryxService 
db.createUser({user:'user', pwd:'password', roles:[{role:'readWrite', db:'AlteryxService'}]})

use AlteryxGallery 
db.createUser({user:'user', pwd:'password', roles:[{role:'readWrite', db:'AlteryxGallery'}]})

use AlteryxGallery_Lucene 
db.createUser({user:'user', pwd:'password', roles:[{role:'readWrite', db:'AlteryxGallery_Lucene'}]})

Here is an example of what to expect when running these commands:

connecting to: localhost:27017/admin  > use AlteryxService switched to db AlteryxService > db.createUser({user:'user', pwd:'password', roles:[{role:'readWrite', db:'AlteryxService'}]}) Successfully added user: {
         "user" : "user",
         "roles" : [
                 {
                         "role" : "readWrite",
                         "db" : "AlteryxService"
                 }
         ]
 } 

After creating the databases and user accounts, close down the MongoDB client:

exit

Feel free to close this Command Prompt as well. We can also shut down the MongoDB daemon (Ctrl+C again - but keep this Command Prompt open) and create a Windows Service for MongoDB. Open a text document and add the following text. Modify any folder listings in your own document to match where you have MongoDB installed:

systemLog:
  destination: file
  path: C:\MongoDB\log\mongod.log
storage:
  dbPath: C:\MongoDB\data
net:
  port: 27017


For more information on the parameters you can set in this file, please visit this link . Save the file in the root MongoDB folder you set up and name it mongod.cfg. In the Command Prompt, run the following command making any modifications to the folder you installed MongoDB and the mongod.cfg file to:

"C:\MongoDB\4.0\bin\mongod.exe" --config "C:\MongoDB\4.0\mongod.cfg" --install

Be sure to include the full path for both files. The Windows Services will not be able to find these files if you use relative paths. After entering the command, there will be a MongoDB entry in your Windows Services list. Open the Windows Services and start up MongoDB.



Now we can connect the Alteryx Service into our new User-Managed MongoDB instance:

  • Open the System Settings Configuration and click Next to Controller->Persistence
  • Select User-managed MongoDB from the Database Type
  • Enter in the Server name and port you have MongoDB installed on. On default, MongoDB will user 27017 to communicate
  • Enter in the Username and Password created for the AlteryxService database



Click Next through the rest of the configuration and Finish to restart the service. When the Alteryx Service starts up, it will populate the database with the required collections.

Feel free to verify your Scheduler and Gallery instances are up and running. If you experience any problems, please contact Alteryx Support .

Thanks to @GaryS,@KevinP, and @ChristineB for proofreading and your advice.
Comments
CristianoJ
Alteryx
Alteryx

I had trouble using the instructions above to create the Windows service.

This command worked for me:

mongod --dbpath="C:\MongoDB\data" --logpath="C:\MongoDB\log\mongod.log" --install

alberto_hernie
7 - Meteor

Hi @CristianoJ,

 

Thanks for that final line of code, it works fine and saved my day getting mongodb installed and running!

 

Regards,

Alberto