Accessing MongoDB via AnyLog
Connect AnyLog to MongoDB for blob storage, using the same connect/create/drop workflow as a SQL database, plus a worked mapping-policy example for image/video data from EdgeX.
` annotation accordingly (dropped description, which was specific to drawing a bbox overlay that doesn’t apply to plain video) | |
| 2026-07-28 | Ori Shadmon | Reconciled the dbms/table names across steps 3, 6, and 7 — they previously named three different targets (test.edgex_data from the mapping policy, ntt.deeptector in the published payload, edgex.images in the query), meaning the walkthrough as written would publish data to one place and query an empty one. Updated the payload and query to match the policy’s fixed target (test.edgex_data), since that’s the one actually enforced — flag if the intent was instead to make the policy dynamic (bring [dbms]/bring [table]) so the payload’s own values would be the ones that matter. Noted new evidence on User-Agent vs AnyLog-Agent (now 2-of-3 examples across the doc set favor AnyLog-Agent) | |
| 2026-07-28 | Ori Shadmon | Fixed !default_dbms being used in step 2 before it’s defined (moved the assignment earlier); quoted three unquoted dictionary-variable references in the mapping policy JSON (id/dbms/table — same bug fixed twice elsewhere this session); fixed "default": "now" → "now()" to match every other example’s function-call convention; moved the source field into schema (it was a sibling of schema rather than a member of it, and the only field of its kind missing a type) — flag if source is meant to be a distinct top-level concept instead. Added a missing example for step 1 and typo/grammar fixes | |
| 2026-07-20 | Eric Aquaronne | added change log | 2.0.2606 |
—>
MongoDB is a schema-less physical database that’s intended for document-oriented data. The NoSQL logic stores data in a flexible BSON (Binary JSON) format, allowing for dynamic schemas and easy adaptation to changing application needs.
For most internal or application-embedded uses, you can use the Community Edition for free under SSPL without needing a commercial license, as long as you are not offering MongoDB itself as a hosted service.
Using MongoDB
Unlike other blob storage options integrated with AnyLog, MongoDB has seamless compatibility with SQL databases due to its nature. Object storage (S3, MinIO, Akave) holds opaque blobs with no internal structure to query, while MongoDB’s documents are already field-structured, mapping much more directly onto SQL’s row/column model — making it a great tool to demonstrate the relationship between data and blob storage.
MongoDB has the same interaction commands with AnyLog as a SQL database for dis/connecting and creating / dropping databases (collections in MongoDB) and tables.
- Connect to SQL-based database
default_dbms = test
connect dbms !default_dbms where type=psql and user=anylog and password=demo and ip=127.0.0.1 and port=5432
- Connect to MongoDB ```anylog mongo_db_ip = 127.0.0.1 mongo_db_port = 27017 mongo_db_user = admin mongo_db_passwd = passwd
<connect dbms !default_dbms where type=mongo and ip=!mongo_db_ip and port=!mongo_db_port and user=!mongo_db_user and password=!mongo_db_passwd
``` Note that the logical “database” for blobs and SQL need to be the same. However, the blob database would be annotated with
blob_[db name]when doingget databases.
- Declare Policy (based on data coming from EdgeX)
policy_id = image-data
default_dbms = test
table_name=edgex_data
<mapping_policy = {
"mapping": {
"id": "!policy_id",
"dbms": "!default_dbms",
"table": "!table_name",
"readings": "readings",
"schema": {
"source": {
"bring": "[deviceName]",
"default": "12"
},
"timestamp": {
"type": "timestamp",
"default": "now()"
},
"file": {
"blob": true,
"bring": "[binaryValue]",
"extension": "mp4",
"apply": "base64decoding",
"hash": "md5",
"type": "varchar"
},
"file_type": {
"bring": "[mediaType]",
"type": "string"
}
}
}
}>
blockchain prepare policy !mapping_policy
blockchain insert where policy=!mapping_policy and local=true and master=!ledger_conn
Note this policy assigns
dbms/tableas fixed values (!default_dbms/!table_name) rather than pulling them from each incoming payload viabring— so every message ingested through this policy lands intest.edgex_dataregardless of whatdbms/tablefields the payload itself contains.
- Set blobs archiver configurations - The example specifies to store, compress and reuse (based on file hash) blob data within the NoSQL database (MongoDB). ```anylog