Skip to main content
All docs
V24.1

Bind a Report to a MongoDB Instance

  • 3 minutes to read

This topic describes how to bind a report to a MongoDB instance in the Visual Studio Report Designer.

Create a new project and add a blank report to this project. Follow the steps below to bind the report to a MongoDB instance.

Invoke the Data Source Wizard

Click the report’s smart tag, expand the drop-down menu for the Data Source property in the “Report Tasks” list, and click Add Report Data Source.

Invoke the Data Source Wizard

Select the MongoDB Data Source

Select MongoDB in the invoked Data Source Wizard and click Next.

Select the MongoDB Data Source

A reporting application uses the MongoDB.Driver package to supply MongoDB data at runtime. If the driver is not installed in your project, the following wizard page appears:

Install MongoDB driver

Use this page to install the driver.

Specify Connection Properties

Paste the entire string or enter connection fields individually. Refer to the following topic for information on connection string format and options: Connection String URI Format.

Specify connection properties

Save the Connection String

Check the Yes, save a connection as option on the next Data Source Wizard page and specify the name of the connection string to save it. Otherwise, click Next.

Save MongoDB connection

The string is saved to the project’s configuration file and you can use this string when you create a new MongoDB connection.

Reuse MongoDB connection string

Note

For .NET projects, install Microsoft.Extensions.Configuration and Microsoft.Extensions.Configuration.Json to obtain a data connection string from appsettings.json when you select a predefined data connection in the Data Source Wizard.

Specify Data Queries

On the next page, choose database collections that you want to load from the MongoDB instance. Specify the name of the database and database collection in the Database and Collection columns. You can use the Filter column to specify filter conditions for items of the database collections.

The names of queries to database collections should be unique. A string stored in a query’s Collection column is the default name for this query. To create several queries to the same database collection, use the Alias column to specify different names for these queries.

Configure queries to a MongoDB instance

Select Data Fields

This wizard page allows you to select data fields that you want to include in a MongoDB collection and also change their display names.

Select data fields

Use the drop-down menu to select a collection whose data fields you want to configure.

Select data fields - drop-down menu

Enable or disable a checkbox in the Field Name column to include or remove a field from a collection.

Select data fields - configure fields

Use editors in the Field Display Name column to change the default field name.

The MongoDB Data Source Wizard analyzes only the first 100 documents to generate field types. If your MongoDB collection contains more than 100 documents, you can use all of them for type generation. For this, click the Analyze all records button.

The Analyze all records button

Use the Created MongoDB Data Source

The created data source appears in the Field List and Report Explorer.

MongoDB data source in the Field List and Report Explorer

You can bind report controls to fields from this data source. Refer to the following topic for more information: Bind Report Controls to Data.

Modify the Created MongoDB Data Source

You can change connection parameters and modify queries for the created data source. Right-click the data source node in the Field List or Report Explorer and select Configure Connections or Manage Queries.

Modify MongoDB Data Source

Reconfigure the connection parameters or queries in the invoked Connection Editor and click Finish.

Reconfigure MongoDB Data Source

Right-click the data source node and select Rebuild Result Schema to apply the changes.

Rebuild Result Schema