Skip to content

Martini Data Integration MongoDB Service Editor

MongoDB services within Martini facilitate direct read and write operations to a MongoDB database, offering a streamlined approach to database interaction. This guide outlines the steps to create and configure MongoDB services in Martini.

Creating a MongoDB Service

The process of creating a MongoDB service in Martini is designed to be straightforward, enabling developers to quickly set up and execute database operations. Follow these steps to create a MongoDB service:

Launch the MongoDB Service Wizard

  1. In the Martini package explorer, navigate to the code directory (or any subdirectory) where you wish to create the MongoDB service.
  2. Right-click and select New > MongoDB Service. This action launches the MongoDB Service Wizard, guiding you through the setup process.

Configure the MongoDB Service

Within the wizard, you will need to specify key details that define how the service will interact with the MongoDB database:

  • Location: Specifies the directory where the MongoDB service will be saved. Defaults to your current directory.
  • Name: Enter a name for your MongoDB service.
  • Connection Name: Choose the database connection name the service will use during development and, by default, at execution.
  • Database: Specify the MongoDB database name to which the service will connect.
  • Collection: Indicate the MongoDB collection the service will interact with.
  • Query Type: Select the type of MongoDB operation (e.g., read, write, update, delete) the service will perform.

Complete the Service Creation

After filling in all the required information:

Click Finish to complete the creation of your MongoDB service. Your service is now ready for development and execution, enabling you to perform the specified database operations.

Editing MongoDB Services

After creating a MongoDB service, Martini automatically opens the service in the MongoDB Service Editor. This interface is specifically designed for configuring and managing MongoDB operations within Martini.

MongoDB Service Editor Components

The MongoDB Service Editor includes several critical components to help configure your MongoDB service effectively:

1. Connection Drop-down

Select the database connection for the MongoDB service to use when being executed. You can choose the desired database connection from the drop-down list, which only includes registered and started MongoDB databases. To change the target database at runtime, set the input.$martiniConnectionPool property to the name of the desired database connection.

2. Type Drop-down

Determine the specific type of MongoDB operation that the service will execute. The supported types and their descriptions are as follows:

Type Description
Find One Retrieves a single document from MongoDB based on the specified filter. An extra text area appears for entering an optional projection document.
Find Many Retrieves multiple documents from MongoDB based on the specified filter. An extra text area appears for entering an optional projection document, and these services return an input cursor.
Delete One Deletes a single document from a collection based on the specified filter.
Delete Many Deletes multiple documents from a collection based on the specified filter.
Replace One Replaces a single document within a collection based on the specified filter.
Update One Updates a single document within a collection based on the specified filter. An extra text area appears for entering an update document.
Update Many Updates all documents that match the specified filter in a collection. An extra text area appears for entering an update document.
Insert One Inserts a single document into a collection.
Insert Many Inserts multiple documents into a collection. These types of services return an output cursor.
Aggregation Performs aggregation operations against a collection using specified pipelines.

3. Database Drop-down

Allows you to select the database for performing the operation. This choice is used by default both at runtime and during development. It can be overridden at runtime by setting the input.$database input property.

4. Collection Drop-down

Enables selection of the collection to perform the operation against. This selection is used by default at runtime and during development. It can be overridden at runtime by setting the input.$collection input property.

5. Database Tree

Displays the databases (and their sizes on disk), collections (including the total number of documents), and a pre-determined data model that represents the collection within the selected database connection. The model shows the data types in the collection, derived from a schema analysis similar to MongoDB's Compass app.

6. Operation Editor Area

This area varies depending on the MongoDB Service Type selected. It is used to enter BSON documents for the operation, such as filters, projections, updates, or aggregation pipelines.

Testing and Previewing BSON Queries

Martini provides features for testing BSON queries to ensure they meet your requirements:

  • Database Perspective: Use this feature in Martini to test your BSON queries.
  • Export MongoDB Query: Right-click a MongoDB service in the Navigator and choose Export > MongoDB Query for testing outside Martini.

Note on MongoDB Queries

For more detailed information on MongoDB BSON syntax and query capabilities, refer to the MongoDB documentation or the links provided in the Type drop-down descriptions.

MongoDB BSON Editors in Martini

Martini's BSON editors are designed to facilitate the creation and editing of BSON documents for filters, projections, and updates within MongoDB services. These editors are equipped with features to assist in writing accurate and efficient BSON code.

BSON Errors and Warnings

Martini's BSON editors are intelligent enough to detect syntax errors or potential issues in your BSON documents. Here's how errors and warnings are managed:

  • Error Indicators: When Martini identifies incorrect BSON syntax, it marks the issue with icons in the gutter and underlines the problematic syntax in yellow (warnings) or red (errors).
  • Tooltip Assistance: Hovering over an error or warning icon or the underlined syntax itself displays a tooltip. This tooltip provides detailed information about the detected issue, helping you understand and resolve syntax errors effectively.
  • Suggestions: For certain issues, Martini may also offer suggestions for fixing errors directly within the tooltip. This includes suggestions for correcting operators or adding necessary fields to your BSON document.

Content-assist Feature

To enhance the BSON editing experience, Martini's BSON editors include a content-assist feature that simplifies the coding process:

  • Functionality: By pressing Ctrl+Space, you can activate the content-assist feature, which provides you with suggestions for completing operators, field names, and other BSON components.
  • Auto-Completion: The content-assist feature helps in auto-completing your code, making it quicker and easier to write accurate BSON documents.
  • Descriptive Comments: Alongside suggestions, the content-assist popup includes brief comments describing each option, aiding in the selection of the appropriate BSON elements for your query or update document.

The BSON editors in Martini are specifically tailored to enhance productivity and ensure the accuracy of MongoDB queries and updates. By leveraging error detection, tooltip assistance, and content-assist features, developers can streamline the process of working with BSON documents, leading to more efficient and error-free MongoDB service creation.

Inputs and Outputs for MongoDB Services

MongoDB services in Martini, like regular services, feature dynamic inputs and outputs that adjust based on the operation type, filter, and any specified updates or projections. These services also support special input and output properties that can be manipulated at runtime to tailor the service's behavior.

Built-in Input and Output Properties

Below is a table outlining the built-in input and output properties available for MongoDB services, highlighting their applicability and function:

Property Type Applicable Operations Description
$martiniConnectionPool Input All The name of the database connection.
$database Input All The MongoDB database to use.
$collection Input All The MongoDB collection to use.
$clientSession Input All The ClientSession to use against the service.
$upsert Input Replace One, Update Indicates whether to upsert the replacement to the collection.
replacement Input Replace One, Update The model to replace the existing document in the collection.
deleteCount Output Delete The number of documents deleted.
acknowledged Output Delete Indicates if the delete was acknowledged.
matchedCount Output Replace One, Update The number of documents matched by the filter.
modifiedCount Output Replace One, Update The number of documents modified (can be null).
upsertedId Output Replace One, Update The _id of the inserted document, if any, otherwise null.
insert Input Insert One The document to insert.
_id Output Insert One The _id of the inserted document, or null.
batchSize Input Insert Many The batch size before inserting documents (default is 10,000).

Parameterized Queries

Martini supports parameterized BSON within MongoDB services, offering flexibility by allowing values within BSON documents to be dynamically set via input properties.

Implementing Parameterized Inputs

To use a parameterized input in a BSON document, replace the value you wish to parameterize with a placeholder in the format {{parameterName}}. This converts the value into an input property within the MongoDB service. For instance, to parameterize CategoryID:

1
2
3
{
    "CategoryID" : "{{myInputProperty}}"
}

Specifying Property Types

By default, parameterized inputs are of type Object. To specify a different data type, include the type in the parameter placeholder:

1
2
3
{
    "CategoryID" : "{{myInputProperty:string}}"
}

As BSON documents are modified to include parameterized inputs, corresponding input properties will be automatically generated and reflected in the Inputs and Outputs view of the service editor.

Tips for Using MongoDB Services in Martini

  • Model Creation: To generate a model representing a MongoDB collection, right-click on the desired collection in the Database tree and select "Export to Model." This feature is useful for creating structured inputs and outputs based on the collection's schema.

By incorporating these capabilities, developers can create more adaptable and powerful MongoDB services within Martini, leveraging dynamic inputs and outputs as well as the flexibility of parameterized queries.