MongoEntityService<T> is an abstract class that sits between MongoService and the concrete service classes. It adds the low-level database primitives (_create, _count, _findById, _findMany, _update, _replace, _delete…), the interceptor-aware _executeCommand loop, and the lifecycle hooks called by MongoCollectionService and MongoSingletonService.
You do not extend it directly. Extend MongoCollectionService or MongoSingletonService instead.
import { MongoEntityService } from '@opra/mongodb';
Hierarchy: ServiceBase → MongoService → MongoEntityService
Lifecycle hooks
Override these in MongoCollectionService or MongoSingletonService subclasses. The base implementations are no-ops.
| Hook | Signature |
|---|
_beforeCreate(command) | (CreateCommand<T>) => Promise<void> |
_afterCreate(command, result) | (CreateCommand<T>, PartialDTO<T>) => Promise<void> |
_beforeReplace(command) | (ReplaceCommand<T>) => Promise<void> |
_afterReplace(command, result) | (ReplaceCommand<T>, PartialDTO<T>) => Promise<void> |
_beforeUpdate(command) | (UpdateOneCommand<T>) => Promise<void> |
_afterUpdate(command, result) | (UpdateOneCommand<T>, PartialDTO<T> | undefined) => Promise<void> |
_beforeUpdateMany(command) | (UpdateManyCommand<T>) => Promise<void> |
_afterUpdateMany(command, affected) | (UpdateManyCommand<T>, number) => Promise<void> |
_beforeDelete(command) | (DeleteCommand<T>) => Promise<void> |
_afterDelete(command, affected) | (DeleteCommand<T>, number) => Promise<void> |
_beforeDeleteMany(command) | (DeleteCommand<T>) => Promise<void> |
_afterDeleteMany(command, affected) | (DeleteCommand<T>, number) => Promise<void> |
Interfaces
MongoEntityService.Options
Identical to MongoService.Options. No additional properties.
Command interfaces
Command objects are passed to lifecycle hooks. Each interface extends MongoService.CommandInfo and narrows the crud discriminant.
CreateCommand<T>
| Property | Type |
|---|
crud | 'create' |
input | PartialDTO<T> |
options | CreateOptions |
CountCommand<T>
| Property | Type |
|---|
crud | 'read' |
options | CountOptions<T> |
DeleteCommand<T>
| Property | Type |
|---|
crud | 'delete' |
documentId | AnyId |
options | DeleteOptions<T> |
DistinctCommand<T>
| Property | Type |
|---|
crud | 'read' |
field | string |
options | DistinctOptions<T> |
ExistsCommand<T>
| Property | Type |
|---|
crud | 'read' |
documentId | AnyId |
options | ExistsOptions<T> |
FindOneCommand<T>
| Property | Type |
|---|
crud | 'read' |
documentId | AnyId |
options | FindOneOptions<T> |
FindManyCommand<T>
| Property | Type |
|---|
crud | 'read' |
options | FindManyOptions<T> |
UpdateOneCommand<T>
| Property | Type |
|---|
crud | 'update' |
documentId | AnyId |
input | MongoPatchDTO<T> (mutually exclusive with inputRaw) |
inputRaw | mongodb.UpdateFilter<T> (mutually exclusive with input) |
options | UpdateOneOptions<T> |
UpdateManyCommand<T>
Same shape as UpdateOneCommand<T> but without documentId.
ReplaceCommand<T>
| Property | Type |
|---|
crud | 'replace' |
documentId | AnyId |
input | PartialDTO<T> |
options | ReplaceOptions<T> |