Skip to content

Add typed MongoDB and search packages so applications stop wrapping the SDK - #41

Merged
liran merged 3 commits into
mainfrom
feat/mongodb-search-packages
Nov 12, 2026
Merged

liran merged 3 commits into
mainfrom
feat/mongodb-search-packages

Conversation

@liran

@liran liran commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Every application on Weir ended up writing the same layer over the raw client: building record paths, putting _id first in BSON, turning outcomes into errors, draining cursors and resending conflicts. The new mongodb and search packages provide it once, as small stateless values (Collection[K, T], DB, Index[T], Cluster) built only on the weir package's public API, which stays backend-neutral. The core gains MutationErr, ReadResult.Err, NativeResult.Err, CodeOf, ErrNotFound and ErrInterrupted. It also resends mutations that ended NOT_APPLIED/CONFLICT, since they took no effect, from a budget separate from refusals so contention never starves drain resends.

This is the API proposal; the quick start stays on v0.24.1 until a release. Unit tests use a fake Weir, and the new integration tests passed against Weir main with MongoDB 8.0 and OpenSearch 2.17. With 1024 concurrent transforms of one record, CONFLICT failures fell from 256 to 28–156 on MongoDB and from 384 to 150–297 on OpenSearch across runs; the rest remain because the conflict budget caps resends at one per ten first sends plus a burst of 100. Batch writes are left out for now: concurrent single-record calls already share the Client's streams.

…ent writers

- MutationErr, ReadResult.Err and NativeResult.Err return a *weir.Error;
  CodeOf reads its FailureCode from any error chain.
- ErrInterrupted marks a request an outage cut short after it may have
  begun, including a lost connection, which keeps its gRPC status.
- ErrNotFound is the shared error for a missing record.
- A mutation NOT_APPLIED with CONFLICT took no effect, so the Client now
  sends it again within the existing resend attempts and budget.
Typed, stateless helpers over the backend-neutral weir package:

- mongodb.Collection[K, T]: Get, GetMany, Create, Put, Replace, Delete,
  Update, Transform, Find and Count, with string, integer and ObjectID
  keys; mongodb.DB: Command and Cursor.
- search.Index[T]: the same record methods, Search and Do;
  search.Cluster: Do.

Both packages use only weir's public API and share single-record calls
through internal/record.
@liran liran self-assigned this Nov 11, 2026
- Mark lost connections on shared and multi-record streams ErrInterrupted,
  not only on Native and single-stream calls.
- Resend a Native request whose stream a server refused, as a refusal.
- Give conflict resends a budget of their own, so a hot record never
  uses up the resends of records a draining server refused.
- Add Error.Completion and state when a write certainly took no effect;
  ErrInterrupted only marks an outage.
- Send $db with getMore and killCursors, so cursors work for a DB
  without a Name.
- Keep a confirmed mutation or complete Native result when an RPC error
  follows it.
- Take a zero _id as unset, send []byte search input as raw JSON, and
  point to Do for search totals and aggregations.
- Correct comments and guides that said only refusals are resent.
@liran
liran merged commit 8291553 into main Nov 12, 2026
3 checks passed
@liran
liran deleted the feat/mongodb-search-packages branch November 12, 2026 00:47
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