Repository navigation
v4.1.0
mongo4s 4.1.0
The aggregation vocabulary MongoDB added in 5.x–7.0 — the ranking and statistical accumulators, window functions,
$fill, $redact and the concise $lookup — plus bitwise updates and filters. Binary compatible with 4.0.0,
checked by MiMa with no exclusions. Upgrade notes:
COMPATIBILITY.md.
libraryDependencies += "org.mongo4s" %% "mongo4s-core" % "4.1.0"New features
- Accumulators —
top/bottomandtopN/bottomNrank by aSortand output a field;firstN/lastN,
maxN/minN;medianandpercentilewith the server'sapproximatemethod;stdDevPop/stdDevSamp;
mergeObjects. The statistical ones compile only on a numeric field. - Window functions —
WindowFunction.rank,denseRank,documentNumber,shift,locf,linearFill,
derivative,integral,expMovingAvg/expMovingAvgAlpha, given tosetWindowFieldsbeside the accumulators.
Putting one in a$group, where the server refuses it, does not compile. $fill— by a value, by the last value seen, or linearly between neighbours, per partition, through
FillOutput. The sort-driven methods are refused without asortBy.$redact, withStage.Descend/Prune/Keepfor the expression's answers.Stage.lookupWithKeys—$lookupthat joins onlocalField/foreignFieldand narrows with a sub-pipeline.
Both keys are typed, so joining anObjectIdto aStringis a compile error.$bit—bitAnd/bitOr/bitXor— and the$bitsAllSet/$bitsAnySet/$bitsAllClear/$bitsAnyClear
filters, on integer fields only throughBitwiseOf.Filter.jsonSchema.- The fake simulates the new accumulators except
median/percentile, and$fill,$bitand the$bits
filters — each pinned by a parity spec against MongoDB 8.2. Window functions,$redact,$jsonSchema,
medianandpercentilethrowUnsupportedOperationExceptionnaming what was asked for.
Bug fixes
- The fake was not safe to share between fibers. Concurrent inserts lost documents or threw, a duplicate
_id
or unique key could get through twice, and concurrent$incs lost updates. Every operation now runs atomically,
so a counter or a work queue claimed throughfindOneAndUpdatebehaves under contention as it does against a
server.
Benchmarks
Re-measured on 4.1.0 against mongo4cats 0.8.0, with the machine, server and every library version stated —
BENCHMARKS.md.
WireCodecto real BSON bytes: 2.4–3.2× faster than eithermongo4catscodec, up to 6.4× less allocation.- Single-document operations against a real MongoDB land level for all six stacks.
- Bulk reads pull ahead:
mongo4catsallocates 2.1–6.0× more onfindAll/findStreamand readsfindAll
1.13–1.35× slower. Itsfind(...).streamon cats-effect runs at 1,626 ops/s againstmongo4s's
3,174 —0.8.0closed most of the gap0.7.18had (392 ops/s), not all of it.
Compatibility
mongodb-driver-reactivestreams5.13.0;kyo1.0.0-RC7.mongo4s-kyoremains outside the binary
compatibility promise while kyo is on a release candidate.Accumulator,Filter,UpdateandStagehave new cases, so an exhaustive match over one of them warns.setWindowFieldstakesWindowFields, the common parent ofWindowOutputandWindowFunction; every existing
call compiles unchanged.Scala 3.9 LTS; building requiresJDK 25. Tested against JDK 25 and MongoDB 8.2.