_id
field from the ObjectId
to a string
.createdOn
, updatedOn
, and deletedOn
timestamps for CUD operations;deletedOn
field;_outbox
postfix that stores all CUD events for implementing the transactional outbox pattern;db
that does two things:
createService
to create different Services to work with MongoDB;createService
method returns the service instance. It accepts two parameters: collection name and ServiceOptions.
node-mongo
is that each create, update or delete operation publishes a CUD event.
${collectionName}.created
${collectionName}.updated
${collectionName}.deleted
eventBus
(Node.js EventEmitter instance);eventBus
.{ outbox: true }
when creating a service;_outbox
postfix;watch
(method for working with Change Streams) on the outbox table;in-memory
events. When your application becomes tougher you should migrate to transactional
events.ServiceOptions
Option | Description | Default value |
---|---|---|
skipDeletedOnDocs | Skip documents with the deletedOn field | true |
schemaValidator | Validation function that will be called on data save | - |
publishEvents | Publish CUD events on save. | true |
addCreatedOnField | Set the createdOn field to the current timestamp on document creation. | true |
addUpdatedOnField | Set updateOne field to the current timestamp on the document update. | true |
outbox | Use transactional events instead of in-memory events | false |
escapeRegExp | Escape $regex values to prevent special characters from being interpreted as patterns. | false |
collectionOptions | MongoDB CollectionOptions | {} |
collectionCreateOptions | MongoDB CreateCollectionOptions | {} |
CreateConfig
ServiceOptions
parameters for create operations.
ReadConfig
ServiceOptions
parameters for read operations.
UpdateConfig
ServiceOptions
parameters for update operations.
DeleteConfig
ServiceOptions
parameters for delete operations.
InMemoryEvent
InMemoryEventHandler
OnUpdatedProperties