MongoDB API
Overview
The Qarbine driver for the MongoDB API permits either MongoDB Query Language or SQL queries. The latter is only supported when the endpoint is MongoDB Atlas SQL. Qarbine previews the query to determine which underlying endpoint service to call.
A collection in MongoDB is analogous to a table in relational databases. However, collections are more flexible. They don’t enforce a strict schema unless configured to do so. Each collection is associated with one MongoDB database.
MongoDB API databases store data as JSON/BSON documents. Each document represents a record and can have varying fields. Unlike traditional relational databases, where adding a field means altering the table structure, MongoDB allows flexible schema changes. Documents can be nested to express hierarchical relationships and store structures like arrays. Qarbine is perfectly fine with such nesting and dynamic answer sets.
The MongoDB Query Language (MQL) aggregation pipelines interface enables complex data transformations. Pipelines consist of stages (e.g., $match, $group, $project) that process data sequentially. Developers and others skilled in MQL can natively use pipelines for analytics, data flows, and custom aggregations. For more details on the various stages see https://www.mongodb.com/docs/atlas/atlas-stream-processing/stream-aggregation/.
MongoDB API databases provide many options for high availability which vary by vendor. The use of replica sets, sharding and indexes are activities “behind” the connection string. In general this functionality is transparent to Qarbine and other applications.
The MongoDB API Tutorial has additional information on using Qarbine with MongoDB API supporting databases.
MongoDB Querying Language
Qarbine supports direct, native MongoDB queries. This is the best way to access the full power of the MongoDB data platform, especially the aggregation pipeline. In general all MongoDB query constructors are supported. For reference see
https://www.mongodb.com/docs/manual/tutorial/query-documents/
The data source below retrieves a list of portfolios.
Here is a query for a portfolio collection that takes advantage of the MongoDB document model features.
db.portfolio.find( {cash: {$gt: 2000}, isIRA: false } )
A sample portfolio document with embedded documents and arrays may look like
The query results can directly feed a Qarbine analysis template which indicates how to iterate through the documents, interact with them using formulas, and format the results. The report “just works” like you’d expect because it uses the same data model as your application! Qarbine can handle any data shape and has lots of conditional configuration as well. The query is a one liner using MongoDB Query Language. It can be super painful to even attempt to use legacy SQL tools with the document model and dynamic data structures enabled by MongoDB.
See the Tutorials area for one describing an example using a MongoDB API data source, template, and prompt.
Reviewing the Generated Specification
You can enter criteria of the form “EXPLAIN ….” to have the query processed and have the returned answer set be the underlying final query specification. A convenient way of specifying this is to have “explain” on the first line and the rest of your SQL on the next lines.
explain
db.foo.find(...)
Then simply “comment out” the first line when not in use
// explain
db.foo.find(...)
Another way to get the specification is to press ALT and click . Any “explain SELECT” or “explain: true” takes precedence over the ALT-click interaction.
MongoDB Atlas™ SQL Querying
The Qarbine integration with MongoDB also supports the MongoDB Atlas SQL interface as well. Simply enter the Atlas SQL statement and click “Run”. Qarbine recognizes the query as SQL oriented and calls the appropriate MongoDB API.
For information on the MongoDB Atlas SQL interactions see https://www.mongodb.com/docs/atlas/data-federation/query/sql/language-reference/