node-mongo
Changelog
Release history and updates for the node-mongo package.
- You can now pass TypeScript generics to all service methods for precise type inference and enhanced type safety. This helps you catch mistakes at compile time and improves your development experience.
- Added
escapeRegExp
option to service methods, enabling automatic escaping of$regex
filter values to prevent special characters from being interpreted as patterns.
Before
After
- Upgraded
mongodb
dependency to v6.17.0 and updated related dependencies (mocha, @types/mocha, zod, etc.). - Fixed all known vulnerabilities.
- Upgraded
mongodb
dependency from v4.10.0 to v6.1.0 (requires Node.js >=16.16.0). - Cleaned up legacy MongoDB connection options.
- Improved typings and compatibility for bulk operations and index management.
- Synchronized README.md with the documentation website for consistency and completeness.
- Fixed:
atomic.updateOne
andatomic.updateMany
now usereadConfig
for query validation, ensuring consistent handling of soft-delete and query options.
- Refactored
Service
andDatabase
classes for better type safety:IDocument
now extends MongoDB’sDocument
and requires_id: string
.- Many methods now use stricter generic constraints (
<T extends IDocument>
).
- Added support for custom schema validation via
schemaValidator
inServiceOptions
. - Introduced new config types:
CreateConfig
,ReadConfig
,UpdateConfig
,DeleteConfig
for more granular operation control. - Improved transaction support:
database.withTransaction
now uses default transaction options and better error handling. - Enhanced logging for event publishing and warnings in development mode.
- Internal: Cleaned up and unified method signatures, improved property type checks, and removed legacy/duplicate code.
- Changed all date fields (
createdOn
,updatedOn
,deletedOn
) to use nativeDate
objects instead of ISO strings.
service.find()
optionspage
andperPage
are now optional; defaults are set internally if omitted.
eventBus.onUpdated
now supports generics for improved type safety.service.aggregate()
now returns an array of results directly.
- In-memory event listeners now require an entity name (e.g.,
onUpdated('users', ...)
). - Added logging for published in-memory events.
The release includes a lot of changes to make sure that the package is compatible with the latest MongoDB version. Most notable changes:
- Rewritten in TypeScript
- Removed monk dependency.
- Added mongodb native Node.JS sdk as dependency.
- Added support for transactional events using transactional outbox pattern
- Introduced shared in-memory events bus. It should be used to listen for CUD updates.
- Update dependencies.
Breaking Changes
Manager
- Rename
validateSchema
option tovalidate
. - Change
addCreatedOnField
default totrue
. - Change
addUpdatedOnField
default totrue
.
- Rename
validateSchema
option tovalidate
. - Change
addCreatedOnField
default totrue
. - Change
addUpdatedOnField
default totrue
.
Query Service
- Remove
generateId
method. - Remove
expectDocument
method.
Service
- Remove
update
method. Use updateOne or updateMany. - Remove
ensureIndex
. Use atomic.createIndex. - Remove
createOrUpdate
. Use create or updateOne or updateMany. - Remove
findOneAndUpdate
. Use findOne and updateOne.
Features
Manager
- Add
useStringId
option.
- Add
useStringId
option.
Query Service
- Add more monk’s methods. See full list
Service
- Add generateId method.
- Add updateOne method.
- Add updateMany method.
- Add performTransaction method.
- Add more monk’s methods in
atomic
namespace. See full list
- Update dependencies.
- Add tests.
- Fix required version of the Node.js.
Breaking Changes
- Now, by default, we do not add the fields
createdOn
andupdatedOn
automatically to the model. If you want to save the current behavior, add the appropriateaddCreatedOnField
andaddUpdatedOnField
options to the service definitions.
- Stop using deprecated method
ensureIndex
of themonk
.
- Add ability to create custom methods for service and query service.
- Add tests.