Omniscope Custom Blocks › Inputs/Databases/MongoDB

MongoDB

Reads the documents of a MongoDB collection, all of them or those matching a JSON query, one record per document.

Inputs › Databases Python

Open the demo in Omniscope Download demo.ioz Sample data: placeholder.csv Source on GitHub

Omniscope custom block · Inputs

Application data in MongoDB, and the report needs it as a table? Read a collection, or the documents matching a query, one record per document, with nested parts kept as JSON.

Python · pandas, pymongo · pymongo installed on first run

The problem it solves

Web and mobile applications often keep their data in MongoDB: users, orders, enrolments, events, each a document with nested parts. Reporting on it means getting the documents out as rows, with the identifiers, decimals and dates in forms a report can use.

This block reads the collection (or the documents matching a query) and outputs one record per document.

How it works

What goes in

Enrolments (a MongoDB collection)

Invented enrolment documents for a college, for example:

{
  "_id": ObjectId("6650a1b2c3d4e5f6a7b8c900"),
  "name": "Amira Haddad", "age": 19, "course": "Data Science",
  "fees": NumberDecimal("9250.00"),
  "enrolled": ISODate("2025-09-22T09:00:00Z"),
  "address": {"town": "Leeds", "postcode": "LS2"},
  "modules": ["Statistics 1", "Python for analysts"]
}

10 documents in the invented collection college.enrolments.

The options

Option Demo setting What it does
Connection URL empty A full connection string; when given, used instead of the settings below.
Host, Port 127.0.0.1, 27017 Where the server is.
User, Password, Authentication database empty Sign-in, if the server needs it (admin when the database is empty).
Database, Collection college, enrolments What to read.
Whole collection ticked Read every document; untick to use the custom query.
Custom query {"address.town": "Leeds"} (when unticked) A MongoDB filter in JSON.
Limit empty The most documents to read.

What comes out

Documents (selected)

_id name age course fees enrolled address modules
6650a1b2c3d4e5f6a7b8c900 Amira Haddad 19 Data Science 9250.0 2025-09-22 09:00:00 {"town": "Leeds", "postcode": "LS2"} ["Statistics 1", "Python for analysts"]
6650a1b2c3d4e5f6a7b8c905 Farid Aziz unknown Data Science 11400.5 2025-09-22 09:05:00 {"town": "Bradford", "postcode": "BD7"} ["Databases"]
6650a1b2c3d4e5f6a7b8c906 Grace Liu 19 Geography 9250.0 2025-09-23 09:06:00 {"town": "York", "postcode": "YO10"} []
6650a1b2c3d4e5f6a7b8c907 Harry Dunn 23 Data Science 11400.5 2025-09-24 09:07:00 ["Statistics 1", "Machine learning"]

10 records. With the custom query {"address.town": "Leeds"} and "Whole collection" unticked: 4 records (Amira Haddad, Chloe Evans, Erin Walsh, Jamal Reid).

Where it pays off

Product analytics: Users and events

Read user or event documents from an application's database and report sign-ups and activity.

E-commerce: Orders with nested lines

Read order documents, then expand the nested lines with the JSON blocks to report products and baskets.

Education and membership: Enrolments

Report enrolments per course and fees per town from a student records collection, as in the demo.

Operations: Device and log documents

Pick up readings or logs written to MongoDB by devices and services, filtered by a query.

Use cases describe typical scenarios and are illustrative; the sample data is invented.

Why do this in Omniscope

How it fits into an Omniscope workflow

MongoDB (college.enrolments) → JSON Expand fields (address) → Aggregate (fees by course and town) → Report

Expand the JSON text fields before using their parts; the _id text is a stable key for joins.

Try it

  1. Open the demo project (demo.iox on the demo server, or import demo.ioz from this folder). It holds the block, not connected to any server, and a File block with placeholder.csv: the block's output for the invented collection. The rest of the workflow runs from the File block.
  2. The question: how much in fees comes from each course?
  3. Look at the File block's output: 10 records, address and modules as JSON text, age as text because of the "unknown".
  4. To read your own collection: enter a connection URL (or host, port and sign-in), the database and the collection, and run it. Then connect it in place of the File block.
  5. Untick "Whole collection" and enter a custom query such as {"course": "Economics"}: only those documents arrive.

Running in Omniscope

Omniscope workflow
Omniscope workflow

The demo project's workflow: the block, its sample output in a File block, and a Validate data check on it.

Language and libraries

Python. It uses pandas and pymongo.

pandas is part of Omniscope's Python environment. pymongo (Apache License 2.0) is listed in the manifest's dependencies; Omniscope installs it on first run if it is missing.

Tested

The block is covered by automated tests that run its script against a stand-in for Omniscope's Python API and a stand-in for MongoDB's driver that serves canned documents with ObjectId, Decimal128, dates, objects and arrays (no call reaches a server): the whole collection, a custom query and a limit, a field kept numeric, an emptied connection URL, sign-in without an authentication database, an empty collection, bad queries and settings, a timed-out server, and 100,000 documents.

Reference

Options

NameTypeWhat it does
Connection URLPasswordOptional. A MongoDB connection string, for example mongodb+srv://user:password@cluster0.example.net/. When given, the connection and authentication settings below are not used.
HostTextThe server's name or IP address, for example db.example.com, or 127.0.0.1 for a server on the same machine.
PortWhole numberThe port MongoDB listens on; usually 27017.
UserTextOptional. The user to sign in as; leave empty for a server without authentication.
PasswordPasswordThe user's password.
Authentication databaseTextOptional. The database the user was created in. Empty: admin.
DatabaseTextThe database that holds the collection.
CollectionTextThe collection to read.
Whole collectionYes / noTicked: every document is read and the custom query is ignored. Unticked: only the documents matching the custom query.
Custom queryTextA MongoDB filter in JSON, used when "Whole collection" is unticked, for example {"age": {"$gte": 20}} or {"address.town": "Leeds"}. Names and text need double quotes.
LimitWhole numberOptional. The most documents to read. Empty or 0: no limit.

Outputs

OutputWhat it holds
DocumentsOne record per document, one field per top-level key; objects and arrays as JSON text.