> ## Documentation Index
> Fetch the complete documentation index at: https://ship-jskiller1404-add-ommiting-private-fields-feature.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Changelog

> Release history and updates for the node-mongo package.

<Update label="v3.3.0" description="July 15, 2025">
  * 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.

  ```typescript theme={null}
  const user = await userService.findOne({ _id: '...' });

  // user.subscription is available if defined in schema
  user.subscription

  // Pass a generic to override the provided type
  // TypeScript will enforce the structure you specify:
  const admin = await userService.findOne<Admin>({ _id: '...' });

  // TypeScript Error:
  // Property 'subscription' doesn't exist on type 'Admin'
  admin.subscription
  ```

  * Added `escapeRegExp` option to service methods, enabling automatic escaping of `$regex` filter values to prevent special characters from being interpreted as patterns.

  Before

  ```typescript theme={null}
  const users = await userService.find({
    name: { $regex: 'John\' }, 
  });

  // Throws error 'Regular expression is invalid: \\ at end of pattern'
  // Provided string by user needs to be escaped before query
  ```

  After

  ```typescript {3} theme={null}
  const service = db.createService<User>(DATABASE_DOCUMENTS.USERS, {
    schemaValidator: (obj) => userSchema.parseAsync(obj),
    escapeRegExp: true,
  });

  // No need to escape string before query
  const users = await userService.find({
    name: { $regex: 'John\' },
  });
  ```

  * Upgraded `mongodb` dependency to v6.17.0 and updated related dependencies (mocha, @types/mocha, zod, etc.).
  * Fixed all known vulnerabilities.
</Update>

<Update label="v3.2.0" description="October 10, 2023">
  * 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.
</Update>

<Update label="v3.1.2" description="December 1, 2022">
  * Synchronized README.md with the documentation website for consistency and completeness.
</Update>

<Update label="v3.1.1" description="October 24, 2022">
  * Fixed: `atomic.updateOne` and `atomic.updateMany` now use `readConfig` for query validation, ensuring consistent handling of soft-delete and query options.
</Update>

<Update label="v3.1.0" description="October 17, 2022">
  * Refactored `Service` and `Database` classes for better type safety:
    * `IDocument` now extends MongoDB's `Document` and requires `_id: string`.
    * Many methods now use stricter generic constraints (`<T extends IDocument>`).
  * Added support for custom schema validation via `schemaValidator` in `ServiceOptions`.
  * 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.
</Update>

<Update label="v3.0.4" description="September 7, 2022">
  * Changed all date fields (`createdOn`, `updatedOn`, `deletedOn`) to use native `Date` objects instead of ISO strings.
</Update>

<Update label="v3.0.3" description="August 3, 2022">
  * `service.find()` options `page` and `perPage` are now optional; defaults are set internally if omitted.
</Update>

<Update label="v3.0.2" description="June 24, 2022">
  * `eventBus.onUpdated` now supports generics for improved type safety.
  * `service.aggregate()` now returns an array of results directly.
</Update>

<Update label="v3.0.1" description="June 21, 2022">
  * In-memory event listeners now require an entity name (e.g., `onUpdated('users', ...)`).
  * Added logging for published in-memory events.
</Update>

<Update label="v3.0.0" description="March 28, 2022">
  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](https://github.com/Automattic/monk) dependency.
  * Added [mongodb native Node.JS sdk](https://www.mongodb.com/docs/drivers/node/current/) as dependency.
  * Added support for transactional events using [transactional outbox pattern](https://microservices.io/patterns/data/transactional-outbox.html)
  * Introduced shared in-memory events bus. It should be used to listen for CUD updates.
</Update>

<Update label="v2.1.0" description="October 15, 2020">
  ### Features

  #### Manager

  [createService](API.md#createservice)

  * Add [emitter](API.md#createservice) option.
</Update>

<Update label="v2.0.0" description="September 29, 2020">
  * Update dependencies.

  ### Breaking Changes

  #### [Manager](API.md#manager)

  [createQueryService](API.md#createqueryservice)

  * Rename `validateSchema` option to `validate`.
  * Change `addCreatedOnField` default to `true`.
  * Change `addUpdatedOnField` default to `true`.

  [createService](API.md#createservice)

  * Rename `validateSchema` option to `validate`.
  * Change `addCreatedOnField` default to `true`.
  * Change `addUpdatedOnField` default to `true`.

  #### [Query Service](API.md#query-service)

  * Remove `generateId` method.
  * Remove `expectDocument` method.

  #### [Service](API.md#service)

  * Remove `update` method. Use [updateOne](API.md#updateone) or [updateMany](API.md#updatemany).
  * Remove `ensureIndex`. Use [atomic.createIndex](API.md#atomiccreateindex).
  * Remove `createOrUpdate`. Use [create](API.md#create) or [updateOne](API.md#updateone) or [updateMany](API.md#updatemany).
  * Remove `findOneAndUpdate`. Use [findOne](API.md#findone) and [updateOne](API.md#updateone).

  ### Features

  #### Manager

  [createQueryService](API.md#createqueryservice)

  * Add `useStringId` option.

  [createService](API.md#createservice)

  * Add `useStringId` option.

  #### [Query Service](API.md#query-service)

  * Add more monk's methods. [See full list](API.md#query-service)

  #### [Service](API.md#service)

  * Add [generateId](API.md#generateid) method.
  * Add [updateOne](API.md#updateone) method.
  * Add [updateMany](API.md#updatemany) method.
  * Add [performTransaction](API.md#performtransaction) method.
  * Add more monk's methods in `atomic` namespace. [See full list](API.md#service)
</Update>

<Update label="v1.1.0" description="June 25, 2019">
  * Update dependencies.
  * Fix required version of the Node.js.

  ### Breaking Changes

  * Now `update` function will work via [set](https://docs.mongodb.com/manual/reference/operator/update/set/) operator. It means the new doc will be the result of merge of the old doc and the provided one.
</Update>

<Update label="v1.0.0" description="May 23, 2018">
  * Update dependencies.
  * Add tests.
  * Fix required version of the Node.js.

  ### Breaking Changes

  * Now, by default, we do not add the fields `createdOn` and` updatedOn` automatically to the model. If you want to save the current behavior, add the appropriate `addCreatedOnField` and` addUpdatedOnField` options to the service definitions.
</Update>

<Update label="v0.3.1" description="December 16, 2017">
  * Stop using deprecated method `ensureIndex` of the `monk`.
</Update>

<Update label="v0.3.0" description="October 24, 2017">
  * Add ability to create custom methods for service and query service.
  * Add tests.
</Update>

<Update label="v0.2.0" description="October 12, 2017">
  * Add support of the [joi](https://github.com/hapijs/joi) for validating data schema.
  * Add tests for validating of the schema.
</Update>
