# MongoDB Setup

Start by setting up your MongoDB OpLog so that Alooma can use it to update your data destination, and then configuring OpLog to retain data for at least 4 days.

# Note

Alooma supports MongoDB version 2.6 and higher.

1. Verify that your MongoDB cluster is writing to an OpLog by logging into your MongoDB cluster and typing db.getReplicationInfo(). If it is, the log’s size, latest event timestamp, and so on are displayed and you can skip to Connecting to MongoDB.

Otherwise, an error message is displayed, and you’ll need to set it up:

{ "errmsg" : "neither master/slave nor replica set replication detected" }

2. You'll need to create a role and add permissions to read the databases/collections to the user you'll use for accessing your MongoDB via Alooma. You can create a new user or use an existing user and add the role to the user. For MongoDB versions prior to 3.2.17: Use the following script to create an Alooma user with permission to read the database and its OpLog, This script needs to be executed on the Mongo admin database and you will need to fill in the correct value for db: '' and also specify a value for the password:

Copy
db.createRole({
role: "alooma",
privileges: [
{
resource: {
cluster : true
},
actions: ["listDatabases"]
},
{
resource: {
db: 'local',
collection: 'oplog.rs'
},
},
{
resource: {
db: ''
},
}
],
roles: [
{
db: 'local'
},
{
db: ''
}
]
})

db.createUser( { user : "alooma",
pwd: "",
roles: [ "alooma" ] } )

For MongoDB versions 3.2.17 and above, use the following script to create a new user and set permissions. This script needs to be executed on the Mongo admin database and you will need to fill in the correct values for db: '' and collection: '' and also specify a value for the password:

Copy
db.createRole({
role: "alooma",
privileges: [
{
resource: {
cluster : true
},
actions: ["listDatabases"]
},
{
resource: {
db: 'local',
collection: 'oplog.rs'
},
actions: ['find']
},
{
resource: {
db: '',
collection: ''
},
actions: ['find']
}
],
roles: [
{
db: 'local'
},
{
db: ''
}
]
})

db.createUser( { user : "alooma",
pwd: "",
roles: [ "alooma" ] } )

If you already have a user, you can set the permissions for the "alooma" role like this, substituting the values for <additional DB> and/or <additional collection>, and then make sure the "alooma" role is added to your user:

Copy
db.grantPrivilegesToRole(
"alooma",
[
{
resource: {
)