Changelog¶
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
[7.11.1] - 2026-07-24¶
Fixed¶
find_one_and_update/find_one_and_replace/find_one_and_delete: now correctly targets the sorted document when projection excludes_id(#26)
[7.11.0] - 2026-07-23¶
Fixed¶
MongoClient.close()now clears all cached databases/collections and data stores, freeing memory (#94)MongoClientraisesInvalidOperationon any operation afterclose()(matches pymongo 4.0+ behavior)$toLongnow correctly treats naive datetime as UTC (matches MongoDB behavior)
⚠️ Breaking Change Warning¶
MongoClient.close() behavior change may affect unit tests
The new close() implementation clears internal state and raises InvalidOperation on subsequent operations. This matches pymongo 4.0+ behavior but may break existing tests that:
- Reuse a MongoClient instance after calling close()
- Don't properly manage client lifecycle in test fixtures
- Use context managers (with MongoClient()) and expect state to persist
Migration: Ensure tests create fresh MongoClient instances or avoid calling close() in test teardown unless the client is no longer needed.
[7.10.0] - 2026-07-23¶
Fixed¶
CodecOptions.to_pymongo(): now forwards all 7 params (document_class, tz_aware, uuid_representation, unicode_decode_error_handler, tzinfo, type_registry, datetime_conversion) (#70)CodecOptions: removed NotImplementedError guards for custom type_registry, tzinfo, unicode_decode_error_handler, document_class (#109)CodecOptions: custom document_class now casts returned documents (OrderedDict, SON, etc.) (#95)_bson_encode(): now returns encoded bytes (was discarded)- NaN: array containment now matches NaN values correctly (#16)
- Projection:
$slice/$elemMatchalone now returns only_id+ operator field (MongoDB behavior) (#81) - Decimal128: sort/comparison now works via
to_decimal()conversion (#111)
[7.9.3] - 2026-07-23¶
Added¶
- Test coverage improvements across update operators, aggregation, and collection edge cases
- CI split into mock-only and MongoDB test jobs with separate codecov uploads
Fixed¶
- NaN: array containment now matches NaN values correctly (#16)
- Projection:
$slice/$elemMatchalone now returns only_id+ operator field (MongoDB behavior) (#81) - Decimal128: sort/comparison now works via
to_decimal()conversion (#111) CodecOptions.to_pymongo(): now forwards all 7 params (document_class, tz_aware, uuid_representation, unicode_decode_error_handler, tzinfo, type_registry, datetime_conversion) (#70)CodecOptions: removed NotImplementedError guards for custom type_registry, tzinfo, unicode_decode_error_handler, document_class (#109)CodecOptions: custom document_class now casts returned documents (OrderedDict, SON, etc.) (#95)_bson_encode(): now returns encoded bytes (was discarded)
[7.9.2] - 2026-07-23¶
Removed¶
- pymongo <4 compatibility guards from source code (collection.py, codec_options.py)
- ~74
@skipIf(not helpers.HAVE_PYMONGO)decorators from tests (pymongo no longer optional) - pymongo 4+ skip decorators and version-gated test methods (dead code)
- Simplified always-true version guards (check_keys, try/except fallbacks)
- Bumped minimum pymongo fallback version to 4.11
[7.9.1] - 2026-07-21¶
Added¶
- MkDocs documentation site with Material theme (docs, dark mode, search, code copy)
- GitHub Pages auto-deploy via GitHub Actions on push to develop
make clean-coveragetarget to remove.coverageand*,coverfiles
Changed¶
- Documentation migrated from flat markdown files to structured MkDocs site
- New pages:
docs/index.md,docs/installation.md,docs/contributing.md
[7.8.2] - 2026-07-20¶
Added¶
find()positional projection$: returns first matching array element (#114)$sizeprojection operator: filters documents by array length in find() (#78)- Aggregation dot notation: verified
$projectand$addFieldsnested field extraction (#118)
7.8.1 - 2026-07-20¶
Fixed¶
bulk_write:upserted_idskeys now use real operation index instead of sequential count (#60)DuplicateKeyError: now includesdetailsdict withkeyPatternandkeyValuematching pymongo format (#88)
[7.9.0]¶
Fixed¶
$group: missing properties in subdocument no longer nullify the entire object (#66)$group: falsey_idvalues (0,"",false) handled correctly (#103)$toLong/$toInt: datetime conversion to epoch milliseconds (#49)$add: datetime + timedelta arithmetic support (#108)$count: accumulator alias for$sum:1in$groupstage (#42)$map+$sumnesting: array flattening in$sum, expression parse fix (#76)$multiply/$add: Decimal128 support in arithmetic operators (#36)find()projection: computed field references ($dotted.path) resolved correctly (#31)$project: nested object inclusion specs return actual values, not literal 1s (#835)$sliceprojection-only: no longer drops other fields from result (#81)$sliceprojection: deep copy prevents database mutation (#30)
[7.8.0]¶
Added¶
QueryProfiler— query capture and index coverage analyzer (docs/profiler.md)- Activated via
MONGOMOCK_PROFILER=1env var withatexitauto-export - Hooks in
Collection._iter_documents,_update_documents,_delete, andaggregate $match - Predicate normalization (values →
?) for query pattern grouping - Filter coverage analysis:
full/partial/noneper query pattern - Sort coverage analysis against index keys
- Partial index support (matches original filter values against
partialFilterExpression) - JSON report with per-collection patterns, indexes, and coverage summary
- Documentation: AGGREGATION.md, API.md, LIMITATIONS.md
- Examples: basic CRUD, aggregation, filtering, TTL, validation
[7.7.0] - 2026-07-06¶
Added¶
ClientSessionand transaction support viaMongoClient.start_session()SessionOptionsandTransactionOptionsclasses- Transaction flow:
start_transaction(),commit_transaction(),abort_transaction() with_transaction(callback)convenience method- Session parameter support in all CRUD operations (insert, update, delete, find, find_one_and_*, bulk_write, aggregate, etc.)
- Transaction isolation: writes within a transaction are buffered and only applied on commit, discarded on abort
- Independent client instances have isolated storage
[7.6.0] - 2026-05-28¶
Added¶
- Geospatial query operators:
$geoIntersectsand$geoWithinfor Point-in-Polygon and Polygon intersection queries - Geospatial distance operators:
$nearand$nearSpherefor proximity queries with distance filtering $geoNearaggregation stage for geospatial aggregation pipelines- Pure Python GeoJSON support: Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, GeometryCollection
- Point-in-polygon ray casting algorithm with hole (inner ring) support
- Haversine distance calculations for spherical geometry
- Euclidean distance calculations for planar geometry
- GeoJSON coordinate validation (longitude [-180, 180], latitude [-90, 90])
- Distance-based sorting on
$nearqueries (implicit unless explicit.sort()provided) - Support for
$maxDistanceand$minDistanceconstraints on proximity queries
[7.5.14] - 2026-05-28¶
Added¶
- Document validation on collections via
validatoroption oncreate_collectionandcollModcommand (mongomock#704) Collection.options()method returns collection options including validator- Documents validated on insert/update against JSON Schema-like validator expressions
validationLevelsupport:strict(default) andmoderatevalidationActionsupport:error(default) andwarn(no-op)bypass_document_validationflag on insert/update operations as per MongoDB API
[7.5.13] - 2026-05-26¶
Added¶
$whereoperator support with Python-based evaluation (simplethis.fieldexpressions)- RuntimeWarning when using
$whereto alert about security implications
Changed¶
- Optimized document cloning by replacing
copy.deepcopywith custom_clone_documenthelper - Significant insert/update performance improvement for bulk operations
[7.5.12] - 2026-05-26¶
Added¶
- Unique index constraints now enforce per-element uniqueness on array fields (multikey behavior)
create_indexes()forwardspartialFilterExpressiontocreate_index()
Fixed¶
create_index()withunique=TrueandpartialFilterExpressionskips non-matching documents during duplicate pre-check- TTL index expiration now resolves nested dotted field names (e.g.,
data.timestamp) correctly
[7.5.11] - 2026-05-25¶
Fixed¶
$renameoperator now supports dot notation for nested field renaming$addToSetpreserves boolean type distinction from numeric 1/0$addToSetwith$eachmodifier handles array values correctly- Query engine accepts
MutableMappingobjects (not justdict) UpdateOne/UpdateManyvalidation raises proper errors for list criteria
[7.5.10] - 2026-05-25¶
Added¶
- Python 3.14 and PyPy 3.10 support in test matrix and classifiers
Database.list_collections()returnsCommandCursorwith collection metadataDatabase.command()now supportsismaster/isMasteradmin commandCursor.explain()returns mock query execution planMongoClientconstructor accepts_storeparameter
Fixed¶
CommandCursor.alivenow tracks exhaustion; returnsFalseafter iteration completelist_database_names()returns active databases including defaultslist_collection_names()filter behavior aligned with PyMongodatabase.command('ismaster')omits replica set keys for standalone mockCursor.explain()caches_compute_resultsto avoid double computation
[7.5.9] - 2026-05-24¶
Fixed¶
- Aggregation missing vs null distinction:
get_value_by_dotreturnsNOTHINGsentinel instead of raisingKeyErrorfor missing fields (mongomock#770) $group,$cond,$switch,$typeoperators now distinguish missing fields fromNonevalues$ifNullnow correctly handlesNOTHING(missing) as nullish$arrayElemAtreturnsNOTHINGfor out-of-bounds indices instead of raisingKeyError_parse_or_nothingmethod removed; replaced byparse()which returnsNOTHINGdirectlyignore_missing_keysparameter removed from_Parserand_parse_expression
[7.5.8] - 2026-05-24¶
Added¶
Database.__iter__returnsself,Database.__next__raisesTypeError, matching PyMongo behavior (closes #64)- 48+ edge-case tests for
$[]positional all andarrayFiltersoperators
Fixed¶
_lookup_array_filternow handles dot-notation filter keys (e.g.,{'e.x': {'$gte': 1}})_lookup_array_filternow handles$and/$orlogical operators in array filter specs_array_filter_appliesnow stripsfilter_idprefix from$and/$orsubfilters_update_document_fields_positionalno longer overwrites thesubdocumentparameter withcurrent_doc, preventing incorrect subdocument carry-over between fields
[7.5.7] - 2026-05-24¶
Fixed¶
Database.__bool__raisesNotImplementedError, matching PyMongo behavior (closes #64)MongoClient.drop_databaseusesis not Noneinstead of truth check on Database object (closes #64)
[7.5.5] - 2026-05-23¶
Fixed¶
$inoperator now correctly handles NaN values in query matching — NaN matches NaN (closes #105)$inoperator no longer coerces across BSON types (e.g.,1no longer matchesTrue)- Aggregation
$inexpression operator uses NaN-aware comparison (closes #105) $[]all-positional array update operator implemented for$set/$unset/$inc/$pop/$bit/$max/$min(closes #128)arrayFiltersparameter now supported forupdate_one/update_manywith$[<id>]pattern (closes #126)$projectstage no longer falsely rejects{_id: 1}in exclusion projections (closes #122)$concatArraysnow raisesOperationFailureon empty argument list (closes #107)$exp/$pow/$modaggregation operators wrapOverflowErrorasOperationFailure(closes #134)$toDoubleconversion wrapsOverflowErrorfor huge integers (closes #134)pandas.NaTvalues in documents no longer crash comparison/sort — treated as datetime type (closes #135)- Test
DBRefstub made immutable —__setattr__raisesAttributeError, matching realbson.DBRef(closes #83) bool(collection)now raisesNotImplementedError, matching PyMongo behaviorDatabaseandCollectionno longer rely on truthiness (or) for optional parameter defaults, ensuring compatibility with objects that forbidbool()Database.write_concernproperty added, matching PyMongo Database API
[7.5.4] - 2026-05-23¶
Added¶
$bitupdate operator — bitwise AND/OR/XOR on document fields (mongomock#891)$bitAnd,$bitOr,$bitXor,$bitNotaggregation expression operators for bitwise operations$stdDevPopand$stdDevSampgroup/project accumulator operators — closes #71
Changed¶
- Upstream compatibility: tests now import
mongomock_ng as mongomockvia alias +sys.modulesshim in conftest, enabling test reuse with upstreammongomockrepo.MongoClient.__repr__outputsmongomock.MongoClient(...)to match.
[7.5.3] - 2026-05-23¶
Added¶
$unionWithaggregation pipeline stage with string and{coll, pipeline}syntax — closes #87$trim,$ltrim,$rtrimstring expression operators — closes #112$toDatetype conversion expression operator (standalone, previously only via$convert{to: 9}) — closes #85;$getFieldfield expression operator with string shorthand and{field, input}syntax — closes #25
Security¶
$functioncustom aggregation expression now raisesNotImplementedErrorwith security advisory instead of silently accepting
[7.5.2] - 2026-05-21¶
Added¶
$indexOfArrayaggregation operator and$concatArraysarray-literal parsing improvements — replicates mongomock#739 and #931; closes #188, #148, #107
Fixed¶
$addToSetgroup accumulation preserves falsey values while still ignoring missing fields — closes #133
[7.5.1] - 2026-05-21¶
Added¶
$replaceWithaggregation stage and update-pipeline stage aliasing$replaceRootsemantics — closes #96, #37$mergeaggregation stage withinto,on,whenMatched(replace/merge/keepExisting/fail) andwhenNotMatched(insert/discard/fail) support;whenMatched: pipelineremains unimplemented — closes #89$dateAdd,$dateSubtract,$dateDiff,$dateTrunc, and$dateFromStringaggregation date operators — replicates mongomock#815, #817, #772, #902; closes #181, #179, #185, #156, #110, #24
Changed¶
- Refactor
$replaceRootto share root-replacement expression handling with$replaceWith
[7.4.1] - 2026-05-21¶
Changed¶
- Drop Python 3.14 from test matrix and classifiers — not yet stable, incompatible with runtime dependencies
- Add pymongo 4.12.0 and 4.14.0 to hatch-test matrix for broader compatibility coverage
Fixed¶
- TTL document expiry no longer crashes on Python 3.13 — normalize naive datetimes to UTC-aware before subtraction in
_value_meets_expiry(store.py) - Replace deprecated
datetime.utcfromtimestampwithdatetime.fromtimestamp(..., tz=timezone.utc)in aggregation$convertto date handlers (aggregate.py) - Replace deprecated
datetime.utcnow()withdatetime.now(timezone.utc).replace(tzinfo=None)in helpers and test suite - Fix hatch-test matrix so environment
hatch-test.*-4.11.0correctly installspymongo==4.11.0(missingifclause) find()projection no longer mutates original document data (mongomock#692 — closes #191)$inoperator correctly handles empty-list values (mongomock#795 — closes #184)$sliceaggregation operator evaluates arguments as expressions (mongomock#819 — closes #178)$addToSetwith$eachcorrectly deduplicates repeated values across runs (mongomock#847 — closes #170)$redactaggregation stage now supported (mongomock#860 — closes #169)Cursor.collationmatches PyMongo 4.x method signature (mongomock#895 — closes #158)$inoperator matches whole arrays in document values (mongomock#919 — closes #154)BulkOperationBuilder.add_updateand_updatesupportsortparameter (mongomock#933 — closes #147)- NaN comparison handling in filter
$eqoperator (mongomock#936 — closes #145) - Replace deprecated
datetime.utcnowwithdatetime.now(UTC)on Python 3.11+ (mongomock#944 — closes #144)
[7.4.0] - 2026-05-21¶
Added¶
$lookup: DBRef.$idsupport inlocalField— resolvesrefs.$idthrough DBRef arrays (mongomock#878 — closes #164)$lookup: DBRef$idfiltering support in filter matching (mongomock#884 — closes #162)- DBRef dotted-field traversal in
helpers.get_value_by_dotfor$lookupjoin conditions
[7.3.0] - 2026-05-20¶
Added¶
$setIntersection,$setDifference,$setIsSubset,$anyElementTrue,$allElementsTrueset operators in aggregation (mongomock#737 — closes #189, mongomock#840 — closes #172, mongomock#842 — closes #171)helpers.to_hashable— convert values to hashable representations for set operations
[7.1.1] - 2026-05-20¶
Fixed¶
$setWindowFieldserror message typo$setWindowsFields→$setWindowFields
Added¶
.agents/references/MDB7_COMPAT.md— MongoDB 7+ compatibility gap tracker
[7.2.1] - 2026-05-20¶
Added¶
- Repository reference files (
CHANGELOG.md,README.md,CLAUDE.md, etc.) migrated into.agents/references/for persistent agent context
[7.2.0] - 2026-05-20¶
Added¶
$convert: supportonError/onNull+to: double/bool/date/objectId(mongomock#864 — closes #167)$setWindowFields:$sum/$avg/$min/$max/$first/$last/$push/$addToSet/$count/$documentNumber/$rank/$denseRank+windowbounds (mongomock#821 — closes #176)$fill:method(locf/linear),sortBy,partitionByFieldssupport (mongomock#892 — closes #160)
Changed¶
- Version now defined statically in
mongomock_ng/__version__.py(single source of truth), replacing dynamichatch-vcs— closes #197 - Tag creation automated via
tag-on-mergeworkflow on PR merge todevelop, replacing manualmake release
[7.1.0] - 2026-05-20¶
Added¶
CLAUDE.mdwith token-efficiency techniques for opencode (opencode instructions).github/copilot-instructions.mdmoved to correct location
Fixed¶
$typenow returns"double"forfloatvalues (mongomock#929)$setWindowFieldsno longer produces duplicate documents with multipleoutputfields (mongomock#821)
Added¶
$sortByCountaggregation stage (mongomock#896 — closes #157)$fillaggregation stage (mongomock#892 — closes #160)$convertaggregation operator with type dispatch (mongomock#864 — closes #167)$reducearray aggregation operator (mongomock#820 — closes #177)$setWindowFieldsaggregation stage with$shiftoperator (mongomock#821 — closes #176)$unsetaggregation stage with nested field support (mongomock#925 — closes #151)$typeaggregation operator with date support (mongomock#929 — closes #150)$roundaggregation operator with<place>parameter (mongomock#930 — closes #149)$toObjectIdtype conversion operator (mongomock#935 — closes #146)$timezoneexpression support in date operators (mongomock#822 — closes #175)
[7.0.2] - 2026-05-19¶
Added¶
commentparameter support forfind(),find_one(),count_documents(),estimated_document_count(),distinct(),bulk_write(),insert_one(),delete_one(),update_one(),find_one_and_update(),find_one_and_replace()(mongomock#921, mongomock#922, mongomock#915, mongomock#831)hintparameter support forfind(),find_one(),count_documents(),distinct()(mongomock#922)letparameter support fordelete_one()(mongomock#831)- Accepts
commentandhintvia_IGNORED_FEATURESinnot_implemented.py
Changed¶
- Updated
find()signature to acceptcommentandhintbefore**kwargs
7.0.0 - 2026-05-18¶
Changed¶
- Rebranded from
mongomocktomongomock_ng— all imports must use the new package name - Versioned to against MongoDB 7.0.34 server behavior
- Migrated build system to Hatch with PEP 621
- Replaced
toxwith Hatch matrix testing (Python 3.10–3.13 × PyMongo 3/4/4.11/7.0/latest/none) - Updated CI to GitHub Actions with lint, type-check, test matrix, and code coverage
- Switched code formatting to Ruff
- Updated
hatch.tomltest matrix for PyMongo 4.11 and 7.0 compatibility - Updated
Makefilewith docker and release helpers
Removed¶
- Legacy build files:
setup.py,setup.cfg,tox.ini,.travis.yml
Fixed¶
- Compatibility with PyMongo 4.11 (BSON validation error messages, BulkOperationBuilder)
- Codec options not forwarded to update methods
- mypy type errors
Notes¶
- This is a major release. Consumers should run their project's test-suite against
mongomock-ng7.0.0 and review any deprecation warnings.
4.4.0 - tbd¶
Added¶
- Add support for Python 3.13
Changed¶
- Remove legacy syntax constructs using
pyupgrade --py39-plus
Removed¶
- Remove support for deprecated Python version 3.8
4.3.0 - 2024-11-16¶
Added¶
- Support for aggregation pipelines in updates @maximkir-fl
Changed¶
- Remove legacy syntax constructs using
pyupgrade --py38-plus
Fixed¶
- The Mongo Python driver did refactor the
gridfsimplementation, so that the patched code had to be adapted.
4.2.0 - 2024-09-11¶
Changed¶
- Switch to hatch as build system.
- Switch to PEP 621 compliant project setup.
- Updated the license to ISC.
Removed¶
- The setuptools specific files e.g.
setup.cfgandsetup.pyhave been removed in the scope of the switch tohatch. - Remove support for deprecated Python versions (everything prior to 3.8)