The Bold Reports® allows you to connect to a MongoDB data source.
To configure the MongoDB data source, follow the below steps:
DATA
configuration panel, click on the NEW DATA
button.
MongoDB
data source type.
When you create a new data, the NEW DATASOURCE
panel will show up with basic options,
27017
.Connect
to proceed with query design pane. Now, enter the required query and execute. Its corresponding values will be shown in grid for preview.
Only query mode is supported for MongoDB data source.
Finish
to save the data source with a relevant name to proceed with designing report.
You can set authentication type, either as None or SCRAM or X.509.
If your MongoDB server does not require authentication, choose None under Authentication Type.
If your MongoDB server requires a username, password, and authentication database, choose SCRAM as the Authentication Type and enter the username, password, and authentication database for the server specified Server Name field.
If your MongoDB server uses SSL encryption with client certificates, Choose X.509 under Authentication Type and provide the Client Certificate File and Client Certificate Password for the server specified in the Server Name field.
Enable Allow Self-Signed Certificates if the MongoDB server configured to accept self signed certificates.
You can connect to MongoDB data sources securely using an SSL/TLS connection. This ensures encrypted communication between the client and the MongoDB server, providing a secure method to access remote databases over untrusted networks.
Client Certificate: The SSL certificate used for client authentication when connecting to the MongoDB server.
Client Certificate Password: The password associated with the client certificate, if it is encrypted.
The MongoDB data source in Bold Reports® Designer supports Code Mode for querying data. Internally, the connector uses the MongoDB runCommand
to execute queries on the connected database. Following are few of the sample queries to retrieve data.
Retrieve all documents from a collection
{
find:"products"
}
Filter documents with condition
{
find:"products",
filter:{productId: "PRD123"}
}
Sorting data
{
find:"products",
sort:{price: -1}
}
Filter documents with multiple conditions
{
find: "products",
filter: {
"orderDetails.date": { $gt: ISODate("2022-01-09")},
"orderDetails.status": { $in: ["Shipped", "Processing"] },
$and:[
{"payment.totalAmount": { $not: { $gt: 1000 } }},
{"payment.totalAmount": { $type: "double" }}
]
}
}
Filter documents using parameter
{
find: "orders",
filter: {
"payment.method": @paymentType,
"payment.totalAmount": { $gte: @amount },
"orderDetails.date": { $gte: @greater}
}
}
Filter documents using multi value parameter
{
find: "orders",
filter: {
orderId: { $in: [@param] }
}
}
Lookup (Join) between collections
{
aggregate: "orders",
pipeline: [
{
$lookup: {
from: "customer",
localField: "customerId",
foreignField: "Id",
as: "customerDetails"
}
}
],
cursor: {}
}
Unwind array fields
{
aggregate: "orders",
pipeline: [
{ $unwind: "$items" }
],
cursor: {}
}
Flatten a nested object
{
aggregate: "orders",
pipeline: [
{
$project: {
customerId: "$customer.customerId",
name: "$customer.name",
email: "$customer.email",
phone:"$customer.contact.phone",
street:"$customer.contact.address.street",
city:"$customer.contact.address.city",
state:"$customer.contact.address.state",
postalCode:"$customer.contact.address.postalCode",
country:"$customer.contact.address.country",
}
}
],
cursor: {}
}
Bold Reports® uses MongoDB’s runCommand syntax internally to execute queries. This means you can write your queries in the same format supported by MongoDB’s runCommand. For more advanced query scenarios, you can search online for MongoDB runCommand examples or refer to the official MongoDB documentation. These examples will help you construct queries compatible with Bold Reports’ MongoDB connector.