Skip to content

spike: mongosh --from to query local files via an embedded engine - #2834

Draft
kmruiz wants to merge 4 commits into
mainfrom
spike/smongo
Draft

spike: mongosh --from to query local files via an embedded engine#2834
kmruiz wants to merge 4 commits into
mainfrom
spike/smongo

Conversation

@kmruiz

@kmruiz kmruiz commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Important

This is a PR left to DeepSeek while I was working on something more important. Likely the code is broken in several ways and doesn't follow best practices. The idea is just to understand how feasible is to embed smongo into mongosh for querying unstructured data locally.

What

Spike for the "mongosh as local db": --from ingests local files into an in-process embedded engine and runs the shell against them — no server, no Docker.

mongosh --from ./data.csv --eval 'db.data.find({})'

How

  • Vendors the smongo engine (packages/smongo/) with a minimal MongoDB wire server (OP_MSG/OP_QUERY) exposed to Node via a napi addon, so mongosh's driver connects over localhost TCP.
  • --from <file> starts the engine, ingests each file into db.<file-stem> (CSV/JSON/NDJSON), runs --eval or an interactive session, and tears the engine down on exit.
  • Rejects --from combined with a remote connection string or --nodb.

Notes / limitations

  • Spike only — no release packaging or multi-platform native binaries; the addon must be built locally (see TEST.md).
  • Build artifacts (smongo-node.node, rust/target/) are gitignored.
  • Subset of wire commands implemented; CSV type inference is heuristic.

Full build + run instructions in TEST.md.

image

Vendors the smongo Rust engine (smongo-engine) plus a minimal MongoDB
wire-protocol server (OP_MSG/OP_QUERY) exposed to Node via a napi addon,
under packages/smongo. The wire server reimplements just enough of smongo's
PyO3 wire logic against smongo-engine so mongosh's driver can connect to the
embedded engine over localhost TCP without a Python runtime.

Build artifacts (packages/smongo/rust/target/, smongo-node.node) are gitignored.
Adds a --from <file> flag that starts the vendored smongo engine in-process,
ingests CSV/JSON/NDJSON files into collections named after the file stem, and
runs the shell (--eval or interactive) against it with no server. The engine is
torn down and its temp directory removed on exit.

- arg-parser: --from array option; rejects combining it with a connection
  string or --nodb
- cli-repl: embedded/smongo.ts (engine lifecycle) + embedded/parse.ts (file
  parsing); _start() bypasses remote connect and ingests after connecting;
  close() stops the engine and cleans up
- cli-repl: USAGE + i18n text, @mongosh/smongo dependency, webpack external
  for the native addon
- workspace: register packages/smongo in package.json / mongosh.code-workspace
- arg-parser: --from single/multiple parsing and validation (rejects a
  connection string and --nodb); update the array-option list assertion
- embedded/parse.spec.ts: pure-JS tests for CSV/JSON/NDJSON parsing and
  collection-name derivation (no native addon required)
- embedded/smongo.spec.ts: native integration tests (gated on the addon)
  that ingest a CSV and query it over the wire
- TEST.md: compile + run instructions and a feature/limitation summary
@kmruiz kmruiz changed the title Spike: mongosh --from to query local files via an embedded engine spike: mongosh --from to query local files via an embedded engine Sep 4, 2026
handle_aggregate ran Collection::aggregate(), which passes no
CollectionResolver, so $unionWith/$lookup/$graphLookup failed with
'$unionWith requires a CollectionResolver'. Run the pipeline through
DatabaseContext + aggregate_with_db_collection so cross-collection stages can
resolve other ingested collections. Document the support in TEST.md.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant