Skip to main content

MongoEntityService

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: ServiceBaseMongoServiceMongoEntityService


Lifecycle hooks

Override these in MongoCollectionService or MongoSingletonService subclasses. The base implementations are no-ops.

HookSignature
_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>

PropertyType
crud'create'
inputPartialDTO<T>
optionsCreateOptions

CountCommand<T>

PropertyType
crud'read'
optionsCountOptions<T>

DeleteCommand<T>

PropertyType
crud'delete'
documentIdAnyId
optionsDeleteOptions<T>

DistinctCommand<T>

PropertyType
crud'read'
fieldstring
optionsDistinctOptions<T>

ExistsCommand<T>

PropertyType
crud'read'
documentIdAnyId
optionsExistsOptions<T>

FindOneCommand<T>

PropertyType
crud'read'
documentIdAnyId
optionsFindOneOptions<T>

FindManyCommand<T>

PropertyType
crud'read'
optionsFindManyOptions<T>

UpdateOneCommand<T>

PropertyType
crud'update'
documentIdAnyId
inputMongoPatchDTO<T> (mutually exclusive with inputRaw)
inputRawmongodb.UpdateFilter<T> (mutually exclusive with input)
optionsUpdateOneOptions<T>

UpdateManyCommand<T>

Same shape as UpdateOneCommand<T> but without documentId.

ReplaceCommand<T>

PropertyType
crud'replace'
documentIdAnyId
inputPartialDTO<T>
optionsReplaceOptions<T>