>_EXECUTIVE SUMMARY
stryke-mongo is one of the opt-in connector packages in the stryke ecosystem. MongoDB client for stryke. CRUD, aggregation, index admin against any MongoDB 5.0+ standalone, replica set, or sharded cluster. The official mongodb Rust driver ships as a Rust cdylib that stryke dlopens in-process on first use Mongo.
The official mongodb Rust crate pulls in tokio, rustls, a DNS resolver, and the BSON stack. Ships once as an opt-in package.
The public surface decomposes as: 71 direct FFI symbols (authoritative list in [ffi].exports of stryke.toml) plus 4 pure-stryke composites (find_stream, exists, find_value, collection_exists) built over the primitives. Of those, a large fraction are connection-free — URI/namespace parsing, 5 validators, 9 ObjectId helpers, and 13 query/filter builders that emit ready-to-use MongoDB documents with no client at all.
| Surface group | Functions |
|---|---|
| Read paths | find, find_one, find_stream, count, aggregate + composites exists, find_value, collection_exists |
| Write paths | insert_one/many, update_one/many, replace_one, delete_one/many (opts: upsert, array_filters) |
| Atomic findAndModify | find_one_and_update, find_one_and_replace, find_one_and_delete |
| Aggregation helpers | distinct, estimated_count, aggregate_db |
| Admin + diagnostics | collection/db create/drop/rename, index admin (create/drop/list/drop-all), run_command, validate, coll_stats, db_stats, explain, server_status, ping |
| Pure URI/namespace helpers | parse/build/valid/redact_connection_string, parse/build_namespace, escape/unescape_regex |
| Validators | valid_collection_name, valid_database_name, valid_namespace, valid_field_name, valid_connection_string |
| ObjectId helpers (9) | is_valid_objectid, new_objectid, objectid_timestamp, parse_objectid, objectid_compare, build_objectid, objectid_from_time, objectid_max_from_time, objectid_range |
| Query builders (13) | merge_filters, or_filter, build_update, build_sort, build_projection, normalize_index_keys, in_filter, between_filter, build_regex_filter, exists_filter, elem_match_filter, text_filter, not_filter |
~ARCHITECTURE
In-process cdylib design: the stryke side is a thin .stk wrapper that calls FFI symbols on the dlopen'd library. No subprocess, no pipe — calls return on the same thread that made them.
| Layer | Implementation |
|---|---|
stryke wrappers (lib/*.stk) | Thin .stk wrapper (Mongo); exposes typed helpers that serialize args to JSON and parse the response |
cdylib (libstryke_mongo.{dylib,so}) | Single Rust cdylib crate; every public surface fn is an extern "C" fn mongo__<verb>(*const c_char) -> *mut c_char (CRUD/admin verbs + connection-free URI/namespace/ObjectId helpers; authoritative list in stryke.toml) |
| Process model | Library is dlopen'd once per stryke session on first use Mongo; a shared tokio runtime + a mongodb::Client cache keyed by connection URI held in OnceCell; lives until the runtime exits |
| Build | Cargo with [lib] crate-type = ["cdylib"]; publish = false; the package itself ships via s pkg install -g . |
| Install path | ~/.stryke/store/mongo@<version>/ after make install; use Mongo from any stryke script resolves it |
| Tests | zunit-style under t/ with live-service variants when applicable |
| CI | GitHub Actions .github/workflows/ci.yml — cargo fmt + clippy + test, plus stryke pkg install verification |
$WHY OPT-IN (NOT BUILTIN)
The official mongodb Rust crate pulls in tokio, rustls, a DNS resolver, and the BSON stack. Ships once as an opt-in package.
The trade-off is intentional. The core stryke binary stays under ~40 MB precisely because each connector ships separately. Daily-driver work (one-liners, awk replacement, data scripting) doesn't need MongoDB drivers, AWS SDKs, or Spark Connect bindings linked in.
&FFI ENVELOPE
JSON in / JSON out across the FFI boundary. Each Mongo::* wrapper serializes its args to a JSON dict and calls the matching mongo__* symbol on the dlopen'd cdylib; the cdylib returns a JSON CString the wrapper parses. catch_unwind on every call converts panics to JSON errors. The returned CString is freed via the cdylib-exported stryke_free_cstring, wired automatically by rust_ffi::load_cdylib. BSON values round-trip via MongoDB relaxed extended JSON.
# request shape (built by the .stk wrapper)
{"<arg>": ...}
# response shape
{"result": ...} # success — per-fn shape
{"error": "<msg>"} # failure — wrapper die()s with the message
BSON values cross the boundary as MongoDB relaxed extended JSON, so non-JSON types round-trip cleanly: ObjectId as {"$oid": …}, DateTime as {"$date": …}, Decimal128 as {"$numberDecimal": …}, Binary as {"$binary": {base64, subType}}, Regex as {"$regularExpression": {pattern, options}}, Timestamp as {"$timestamp": {t, i}}. The same wrappers can be passed back through filters/updates and are re-parsed to real BSON before the wire.
@DEPENDENCIES
The cdylib links the official driver and the async stack; panic = "abort", lto = "thin", strip = true, codegen-units = 1 in the release profile. Pulled in only by this package — never by core stryke.
| Crate | Version | Role |
|---|---|---|
mongodb | 3 (features: rustls-tls, dns-resolver, compat-3-0-0) | official async MongoDB driver |
bson | 2 | BSON ↔ extended-JSON conversion + ObjectId |
tokio | 1 (rt-multi-thread, macros, io-std, io-util) | shared async runtime held in OnceCell |
futures-util | 0.3 | cursor stream collection |
serde / serde_json | 1 (preserve_order) | FFI JSON envelope (order-preserving) |
anyhow | 1 | error context across the FFI boundary |
once_cell / parking_lot | 1 / 0.12 | runtime + client cache |
/SCOPE
The full per-function reference (read/write/findAndModify/aggregation/admin/pure-helpers/query-builders, with signatures and option lists) is on the Docs page; the README's "Why this is a package" + "API reference" sections are the upstream source of truth. The package is intentionally narrower than the underlying driver — the goal is "useful from a shell pipeline", not "complete API coverage". Not-yet-shipped: Change Streams, multi-doc transactions, bulk_write, GridFS (see the Docs roadmap).
#PROJECT METADATA
| Item | Value |
|---|---|
| Version | v0.21.0 |
| License | MIT |
| Author | MenkeTechnologies |
| Repository | github.com/MenkeTechnologies/stryke-mongo |
| Parent language | strykelang |
| Meta umbrella | MenkeTechnologiesMeta |
| Issues | github.com/MenkeTechnologies/stryke-mongo/issues |