Connecting to MongoDB
Sisense enables easy and quick access to databases, tables and views contained within MongoDB databases, including connecting to the MongoDB database for the Sisense application.
Sisense provides a MongoDB connector for the ElastiCube.
Before connecting to MongoDB database with Sisense, note that MongoDB is an unstructured database, and therefore tables may be flattened with additional tables being created for nested items.
To connect to MongoDB:
- Open Sisense. For a non-local installation, open Sisense on the hosted cloud environment.
- In the Data page, open a ElastiCube or create a new ElastiCube.
In the Model Editor, click . The Add Data dialog box is displayed.
Click MongoDB to open the MongoDB settings.
You can connect to MongoDB using either Basic settings entering the required parameters or by using Advanced settings via a connection string.
Connecting to MongoDB: Basic Settings
In the MongoDB settings area, enter the following information:
Location: Enter IP address of the host where your MongoDB instance is running.
Port: Enter the number of the TCP port that the server uses to listen for client connections.
Database: Enter the name of the database that you want to access (case-sensitive).
Replica Set: If you are connecting to a replica set in your MongoDB implementation, select the Replica Set checkbox and enter the name of the replica set (required field).
Authentication Mechanism: The authentication mechanism to use, No authentication, LDAP, or username and password.
- Username: Enter your username to access your MongoDB.
- Password: Enter your password to access your MongoDB.
- Authentication Source: To use a database other than the admin database to check your credentials, enter the name of the database.
Enable SSL: Select to enable SSL.
Trust Store: Enter the full path of the Trust Store.
Trust Store Password: Enter the password property to your password for accessing the TrustStore.
Metadata Mechanism: This option specifies where the driver looks for the schema definition.
Database: The driver loads the schema definition from the MongoDB database.
Metadata File: The driver loads the schema definition from the JSON file specified in the Local File field or the LocalMetadataFile key
Sampling Method: This property specifies whether the driver starts sampling data from the first or last record when generating a temporary schema definition.
Forward: The driver samples data starting from the first record in the database, then samples the next record, and so on.
Backwards: The driver samples data starting from the last record in the database, then samples the preceding record, and so on.
- Sampling Count: Enter the maximum number of records that the driver can sample to generate a temporary schema definition. When this property is set to 0, the driver samples every document in the database.
- Sampling Interval: Enter the interval at which the driver samples records when scanning through the database to generate a temporary schema definition. For example, if you set this property to 2, then the driver samples every second record in the database.
- Local Metadata File: Enter the full path of a local JSON file containing the schema definition that you want the driver to use when connecting to MongoDB
- Additional Parameters: Enter additional configuration options by appending key-value pairs to the connection string. For example database=TestData;
Connecting to MongoDB: Advanced Settings
Advanced: Enter a JDBC connection string. You must provide the JDBC parameters as semicolon-separated key-value pairs.
- Click Next. A list of tables in the database is displayed. All tables and views associated with the database will appear in a new window.
- From the Tables list, select the relevant table or view you want to work with. You can click next to the relevant table or click Preview to see a preview of the data inside it.
- (Optional) Click + to customize the data you want to import with SQL. See Importing Data with Custom Queries for more information.
- After you have selected all the relevant tables, click Done. The tables are added to your data model.
Connecting to MongoDB with a Schema Editor
If you have a large or complex MongoDB implementation, Sisense recommends connecting to your MongoDB via the Schema editor.
This procedure comprises two main steps:
- Creating a schema definition JSON file.
- Connecting the schema definition to Sisense.
Creating a Schema Definition JSON File
Use a Schema Editor to create a schema definition file in JSON format for your MongoDB.
For more information, see this article about using a schema editor, and the Schema Editor User Guide.
To create the schema:
- Download the schema-editor.zip file from here to your computer.
- Extract the contents of the zip file. You will have a new folder containing the SchemaEditor.jar file and a sub-folder named libs.
Open a command prompt and run the following command:
java -jar SchemaEditor.jar
Run the SchemaEditor on JRE 1.8.0_66 or later. If your JRE is an older version, run the following command:
"C:\Program Files\Java\jre1.8.0_xx\bin\java" -jar SchemaEditor.jar
In the Schema Editor window, under "Create a new Schema Definition", click Create New.
In the Connection URL field, enter the connection string, and click Connect.
Select the collections you want to use and click Sample.
- Add and remove columns as required.
From the File menu, click Save to save the JSON file.
Connecting the Schema Definition JSON File to Sisense
Having created the schema definition JSON file, you can now connect it to Sisense. Doing so ensures that when you connect your MongoDB data source, the correct tables and columns are imported.
To connect the schema definition JSON file to Sisense:
- Open Sisense and, in your ElastiCube, from the Data page, click + Data.
- Add the MongoDB connector.
In the Metadata Mechanism field, select Metadata file.
In the Local Metadata File field, enter the path of the generated JSON file:
- Click Next and complete the wizard.
Connecting to MongoDB Atlas
MongoDB Atlas is a MongoDB cloud service. Sisense supports connections to MongoDB Atlas through the following methods:
- Generic JDBC connector
- MongoDB connector
Both methods are described below.
MongoDB Atlas has the following prerequisites:
- You must whitelist the server IP in Network Access
- You must know the name of the catalog you are accessing (we can only access one per connection)
- You must have a user and password for accessing the catalog
- You must know the Atlas nodes' hosts and ports, which must be open
For more information, see here.
MongoDB Atlas Example Settings
The following is an example of a three node cluster in MongoDB Atlas. This example is used to describe what information you need to provide in Sisense to establish a connection with MongoDB Atlas in Connecting to MongoDB Atlas with the MongoDB Connector.
This example has three nodes:
The username and password are: admin/********.
The database to be accessed in this example is sample_airbnb.
Connecting to MongoDB Atlas with the MongoDB Connector
Using the example above, enter the connection details as follows in the MongoDB Connector settings:
Enter the hosts separated by comma. The port is taken from the Port field using it as a default port. Spaces are ignored.
cluster0-shard-00-00-l2zsn.mongodb.net, cluster0-shard-00-01-l2zsn.mongodb.net, cluster0-shard-00-02-l2zsn.mongodb.net
Enter the hosts with its port. The Port field is ignored. Spaces are ignored.
cluster0-shard-00-00-l2zsn.mongodb.net:27017, cluster0-shard-00-01-l2zsn.mongodb.net:27017, cluster0-shard-00-02-l2zsn.mongodb.net:27017
Port: Ignored if it is specified in the address, otherwise it's used as a default for every host without a port, 27017.
Authentication mechanism: Username and password
Enable SSL: Select this check box.
Click Next to see your database.
- When connecting to MongoDB, your credentials are cached when SSL is enabled.
- When creating a union from the Data Wizard while working with the MongoDB connector, no preview is displayed. You can import both tables individually and then perform a build. The next time you open the Data Wizard the preview is displayed as expected.
Troubleshooting MongoDB Connections
- If you are having problems with timeouts when connecting to MongoDB, try reducing the sample size to 1.
- Use the Schema Editor to selectively sample your database and collections of choice and use the generated schema map for your queries. The driver is intended to sample all the databases it has authentication rights to.