import { EntityManager } from "./EntityManager"; import type { EntityTarget } from "../common/EntityTarget"; import type { ObjectLiteral } from "../common/ObjectLiteral"; import type { MongoQueryRunner } from "../driver/mongodb/MongoQueryRunner"; import type { FindManyOptions } from "../find-options/FindManyOptions"; import type { QueryDeepPartialEntity } from "../query-builder/QueryPartialEntity"; import { InsertResult } from "../query-builder/result/InsertResult"; import { UpdateResult } from "../query-builder/result/UpdateResult"; import { DeleteResult } from "../query-builder/result/DeleteResult"; import type { EntityMetadata } from "../metadata/EntityMetadata"; import type { AggregateOptions, AggregationCursor, AnyBulkWriteOperation, BulkWriteOptions, BulkWriteResult, ChangeStream, ChangeStreamOptions, Collection, CommandOperationOptions, CountDocumentsOptions, CountOptions, CreateIndexesOptions, DeleteOptions, DeleteResult as DeleteResultMongoDb, Document, Filter, FilterOperators, FindCursor, FindOneAndDeleteOptions, FindOneAndReplaceOptions, FindOneAndUpdateOptions, IndexDescription, IndexInformationOptions, IndexSpecification, InsertManyResult, InsertOneOptions, InsertOneResult, ListIndexesCursor, ListIndexesOptions, ObjectId, OptionalId, OrderedBulkOperation, RenameOptions, ReplaceOptions, UnorderedBulkOperation, UpdateFilter, UpdateOptions, UpdateResult as UpdateResultMongoDb } from "../driver/mongodb/typings"; import type { DataSource } from "../data-source/DataSource"; import type { MongoFindManyOptions } from "../find-options/mongodb/MongoFindManyOptions"; import type { MongoFindOneOptions } from "../find-options/mongodb/MongoFindOneOptions"; import type { FindOptionsSelect } from "../find-options/FindOptionsSelect"; import type { ColumnMetadata } from "../metadata/ColumnMetadata"; /** * Entity manager supposed to work with any entity, automatically find its repository and call its methods, * whatever entity type are you passing. * * This implementation is used for MongoDB driver which has some specifics in its EntityManager. */ export declare class MongoEntityManager extends EntityManager { readonly "@instanceof": symbol; get mongoQueryRunner(): MongoQueryRunner; constructor(dataSource: DataSource); /** * Finds entities that match given find options. */ /** * Finds entities that match given find options or conditions. * * @param entityClassOrName * @param optionsOrConditions */ find(entityClassOrName: EntityTarget, optionsOrConditions?: FindManyOptions | Partial | FilterOperators): Promise; /** * Finds entities that match given find options or conditions. * Also counts all entities that match given conditions, * but ignores pagination settings (from and take options). * * @param entityClassOrName * @param options */ findAndCount(entityClassOrName: EntityTarget, options?: MongoFindManyOptions): Promise<[Entity[], number]>; /** * Finds entities that match given where conditions. * * @param entityClassOrName * @param where */ findAndCountBy(entityClassOrName: EntityTarget, where: any): Promise<[Entity[], number]>; /** * Finds entities that match given WHERE conditions. * * @param entityClassOrName * @param where */ findBy(entityClassOrName: EntityTarget, where: any): Promise; /** * Finds entities by ids. * Optionally find options can be applied. * * @param entityClassOrName * @param ids * @param optionsOrConditions */ findByIds(entityClassOrName: EntityTarget, ids: any[], optionsOrConditions?: FindManyOptions | Partial): Promise; /** * Finds first entity that matches given conditions and/or find options. * * @param entityClassOrName * @param options */ findOne(entityClassOrName: EntityTarget, options: MongoFindOneOptions): Promise; /** * Finds first entity that matches given WHERE conditions. * * @param entityClassOrName * @param where */ findOneBy(entityClassOrName: EntityTarget, where: any): Promise; /** * Inserts a given entity into the database. * Unlike save method executes a primitive operation without cascades, relations and other operations included. * Executes fast and efficient INSERT query. * Does not check if entity exist in the database, so query will fail if duplicate entity is being inserted. * You can execute bulk inserts using this method. * * @param target * @param entity */ insert(target: EntityTarget, entity: QueryDeepPartialEntity | QueryDeepPartialEntity[]): Promise; /** * Updates entity partially. Entity can be found by a given conditions. * Unlike save method executes a primitive operation without cascades, relations and other operations included. * Executes fast and efficient UPDATE query. * Does not check if entity exist in the database. * * @param target * @param criteria * @param partialEntity */ update(target: EntityTarget, criteria: string | string[] | number | number[] | Date | Date[] | ObjectId | ObjectId[] | ObjectLiteral, partialEntity: QueryDeepPartialEntity): Promise; /** * Deletes entities by a given conditions. * Unlike save method executes a primitive operation without cascades, relations and other operations included. * Executes fast and efficient DELETE query. * Does not check if entity exist in the database. * * @param target * @param criteria */ delete(target: EntityTarget, criteria: string | string[] | number | number[] | Date | Date[] | ObjectId | ObjectId[] | ObjectLiteral[]): Promise; /** * Creates a cursor for a query that can be used to iterate over results from MongoDB. * * @param entityClassOrName * @param query */ createCursor(entityClassOrName: EntityTarget, query?: ObjectLiteral): FindCursor; /** * Creates a cursor for a query that can be used to iterate over results from MongoDB. * This returns modified version of cursor that transforms each result into Entity model. * * @param entityClassOrName * @param query */ createEntityCursor(entityClassOrName: EntityTarget, query?: ObjectLiteral): FindCursor; /** * Execute an aggregation framework pipeline against the collection. * * @param entityClassOrName * @param pipeline * @param options */ aggregate(entityClassOrName: EntityTarget, pipeline: Document[], options?: AggregateOptions): AggregationCursor; /** * Execute an aggregation framework pipeline against the collection. * This returns modified version of cursor that transforms each result into Entity model. * * @param entityClassOrName * @param pipeline * @param options */ aggregateEntity(entityClassOrName: EntityTarget, pipeline: Document[], options?: AggregateOptions): AggregationCursor; /** * Perform a bulkWrite operation without a fluent API. * * @param entityClassOrName * @param operations * @param options */ bulkWrite(entityClassOrName: EntityTarget, operations: AnyBulkWriteOperation[], options?: BulkWriteOptions): Promise; /** * Count number of matching documents in the db to a query. * * @param entityClassOrName * @param query * @param options */ count(entityClassOrName: EntityTarget, query?: Filter, options?: CountOptions): Promise; /** * Count number of matching documents in the db to a query. * * @param entityClassOrName * @param query * @param options */ countDocuments(entityClassOrName: EntityTarget, query?: Filter, options?: CountDocumentsOptions): Promise; /** * Count number of matching documents in the db to a query. * * @param entityClassOrName * @param query * @param options */ countBy(entityClassOrName: EntityTarget, query?: ObjectLiteral, options?: CountOptions): Promise; /** * Creates an index on the db and collection. * * @param entityClassOrName * @param fieldOrSpec * @param options */ createCollectionIndex(entityClassOrName: EntityTarget, fieldOrSpec: IndexSpecification, options?: CreateIndexesOptions): Promise; /** * Creates multiple indexes in the collection, this method is only supported for MongoDB 2.6 or higher. * Earlier version of MongoDB will throw a command not supported error. * Index specifications are defined at http://docs.mongodb.org/manual/reference/command/createIndexes/. * * @param entityClassOrName * @param indexSpecs */ createCollectionIndexes(entityClassOrName: EntityTarget, indexSpecs: IndexDescription[]): Promise; /** * Delete multiple documents on MongoDB. * * @param entityClassOrName * @param query * @param options */ deleteMany(entityClassOrName: EntityTarget, query: Filter, options?: DeleteOptions): Promise; /** * Delete a document on MongoDB. * * @param entityClassOrName * @param query * @param options */ deleteOne(entityClassOrName: EntityTarget, query: Filter, options?: DeleteOptions): Promise; /** * The distinct command returns returns a list of distinct values for the given key across a collection. * * @param entityClassOrName * @param key * @param query * @param options */ distinct(entityClassOrName: EntityTarget, key: string, query: Filter, options?: CommandOperationOptions): Promise; /** * Drops an index from this collection. * * @param entityClassOrName * @param indexName * @param options */ dropCollectionIndex(entityClassOrName: EntityTarget, indexName: string, options?: CommandOperationOptions): Promise; /** * Drops all indexes from the collection. * * @param entityClassOrName */ dropCollectionIndexes(entityClassOrName: EntityTarget): Promise; /** * Find a document and delete it in one atomic operation, requires a write lock for the duration of the operation. * * @param entityClassOrName * @param query * @param options */ findOneAndDelete(entityClassOrName: EntityTarget, query: ObjectLiteral, options?: FindOneAndDeleteOptions): Promise; /** * Find a document and replace it in one atomic operation, requires a write lock for the duration of the operation. * * @param entityClassOrName * @param query * @param replacement * @param options */ findOneAndReplace(entityClassOrName: EntityTarget, query: Filter, replacement: Document, options?: FindOneAndReplaceOptions): Promise; /** * Find a document and update it in one atomic operation, requires a write lock for the duration of the operation. * * @param entityClassOrName * @param query * @param update * @param options */ findOneAndUpdate(entityClassOrName: EntityTarget, query: Filter, update: UpdateFilter, options?: FindOneAndUpdateOptions): Promise; /** * Retrieve all the indexes on the collection. * * @param entityClassOrName */ collectionIndexes(entityClassOrName: EntityTarget): Promise; /** * Retrieve all the indexes on the collection. * * @param entityClassOrName * @param indexes */ collectionIndexExists(entityClassOrName: EntityTarget, indexes: string | string[]): Promise; /** * Retrieves this collections index info. * * @param entityClassOrName * @param options */ collectionIndexInformation(entityClassOrName: EntityTarget, options?: IndexInformationOptions): Promise; /** * Initiate an In order bulk write operation, operations will be serially executed in the order they are added, creating a new operation for each switch in types. * * @param entityClassOrName * @param options */ initializeOrderedBulkOp(entityClassOrName: EntityTarget, options?: BulkWriteOptions): OrderedBulkOperation; /** * Initiate a Out of order batch write operation. All operations will be buffered into insert/update/remove commands executed out of order. * * @param entityClassOrName * @param options */ initializeUnorderedBulkOp(entityClassOrName: EntityTarget, options?: BulkWriteOptions): UnorderedBulkOperation; /** * Inserts an array of documents into MongoDB. * * @param entityClassOrName * @param docs * @param options */ insertMany(entityClassOrName: EntityTarget, docs: OptionalId[], options?: BulkWriteOptions): Promise; /** * Inserts a single document into MongoDB. * * @param entityClassOrName * @param doc * @param options */ insertOne(entityClassOrName: EntityTarget, doc: OptionalId, options?: InsertOneOptions): Promise; /** * Returns if the collection is a capped collection. * * @param entityClassOrName */ isCapped(entityClassOrName: EntityTarget): Promise; /** * Get the list of all indexes information for the collection. * * @param entityClassOrName * @param options */ listCollectionIndexes(entityClassOrName: EntityTarget, options?: ListIndexesOptions): ListIndexesCursor; /** * Reindex all indexes on the collection Warning: reIndex is a blocking operation (indexes are rebuilt in the foreground) and will be slow for large collections. * * @param entityClassOrName * @param newName * @param options */ rename(entityClassOrName: EntityTarget, newName: string, options?: RenameOptions): Promise>; /** * Replace a document on MongoDB. * * @param entityClassOrName * @param query * @param doc * @param options */ replaceOne(entityClassOrName: EntityTarget, query: Filter, doc: Document, options?: ReplaceOptions): Promise; watch(entityClassOrName: EntityTarget, pipeline?: Document[], options?: ChangeStreamOptions): ChangeStream; /** * Update multiple documents on MongoDB. * * @param entityClassOrName * @param query * @param update * @param options */ updateMany(entityClassOrName: EntityTarget, query: Filter, update: UpdateFilter, options?: UpdateOptions): Promise; /** * Update a single document on MongoDB. * * @param entityClassOrName * @param query * @param update * @param options */ updateOne(entityClassOrName: EntityTarget, query: Filter, update: UpdateFilter, options?: UpdateOptions): Promise; /** * Replaces the entity's ObjectId property name (e.g. "id") with "_id" in a * query object so that `findOneBy({ id: value })` works as expected. * * @param metadata * @param query */ protected replaceObjectIdProperty(metadata: EntityMetadata, query: ObjectLiteral | undefined): ObjectLiteral | undefined; /** * Recursively rewrites a query object, renaming the given property to * "_id" and converting values to ObjectId instances. Walks into $or/$and. * * @param obj * @param propertyName * @param objectIdClass */ private rewriteObjectIdQuery; /** * Converts a query value to ObjectId, handling scalars, arrays, and * MongoDB operator objects (e.g. { $in: [...] }, { $ne: ... }). * * @param value * @param objectIdClass */ private convertToObjectId; /** * Converts FindManyOptions to mongodb query. * * @param optionsOrConditions */ protected convertFindManyOptionsOrConditionsToMongodbQuery(optionsOrConditions: MongoFindManyOptions | Partial | FilterOperators | any[] | undefined): ObjectLiteral | undefined; /** * Converts FindOneOptions to mongodb query. * * @param optionsOrConditions */ protected convertFindOneOptionsOrConditionsToMongodbQuery(optionsOrConditions: MongoFindOneOptions | Partial | undefined): ObjectLiteral | undefined; /** * Converts FindOptions into mongodb order by criteria. * * @param order */ protected convertFindOptionsOrderToOrderCriteria(order: ObjectLiteral): ObjectLiteral; /** * Converts FindOptions into mongodb select by criteria. * * @param selects * @param metadata */ protected convertFindOptionsSelectToProjectCriteria(selects: FindOptionsSelect, metadata: EntityMetadata): ObjectLiteral; /** * Ensures given id is an id for query. * * @param metadata * @param idMap */ protected convertMixedCriteria(metadata: EntityMetadata, idMap: any): ObjectLiteral; /** * Overrides cursor's toArray and next methods to convert results to entity automatically. * * @param metadata * @param cursor */ protected applyEntityTransformationToCursor(metadata: EntityMetadata, cursor: FindCursor | AggregationCursor): void; protected filterSoftDeleted(cursor: FindCursor, deleteDateColumn: ColumnMetadata, query?: ObjectLiteral): void; /** * Finds first entity that matches given conditions and/or find options. * * @param entityClassOrName * @param optionsOrConditions * @param maybeOptions */ protected executeFindOne(entityClassOrName: EntityTarget, optionsOrConditions?: any, maybeOptions?: MongoFindOneOptions): Promise; protected executeFind(entityClassOrName: EntityTarget, optionsOrConditions?: MongoFindManyOptions | Partial | any[]): Promise; /** * Finds entities that match given find options or conditions. * * @param entityClassOrName * @param optionsOrConditions */ executeFindAndCount(entityClassOrName: EntityTarget, optionsOrConditions?: MongoFindManyOptions | Partial): Promise<[Entity[], number]>; }