import { EntityManager } from "./EntityManager"; import { EntityTarget } from "../common/EntityTarget"; import { ObjectLiteral } from "../common/ObjectLiteral"; import { MongoQueryRunner } from "../driver/mongodb/MongoQueryRunner"; import { FindManyOptions } from "../find-options/FindManyOptions"; import { 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 { EntityMetadata } from "../metadata/EntityMetadata"; import { AggregateOptions, AggregationCursor, AnyBulkWriteOperation, BulkWriteOptions, BulkWriteResult, ChangeStream, ChangeStreamOptions, Collection, CollStats, CollStatsOptions, 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 { DataSource } from "../data-source/DataSource"; import { MongoFindManyOptions } from "../find-options/mongodb/MongoFindManyOptions"; import { MongoFindOneOptions } from "../find-options/mongodb/MongoFindOneOptions"; import { FindOptionsSelect, FindOptionsSelectByString } from "../find-options/FindOptionsSelect"; import { 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(connection: DataSource); /** * Finds entities that match given find options. */ /** * Finds entities that match given find options or conditions. */ 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). */ findAndCount(entityClassOrName: EntityTarget, options?: MongoFindManyOptions): Promise<[Entity[], number]>; /** * Finds entities that match given where conditions. */ findAndCountBy(entityClassOrName: EntityTarget, where: any): Promise<[Entity[], number]>; /** * Finds entities that match given WHERE conditions. */ findBy(entityClassOrName: EntityTarget, where: any): Promise; /** * Finds entities by ids. * Optionally find options can be applied. * * @deprecated use `findBy` method instead. */ findByIds(entityClassOrName: EntityTarget, ids: any[], optionsOrConditions?: FindManyOptions | Partial): Promise; /** * Finds first entity that matches given conditions and/or find options. */ findOne(entityClassOrName: EntityTarget, options: MongoFindOneOptions): Promise; /** * Finds first entity that matches given WHERE conditions. */ findOneBy(entityClassOrName: EntityTarget, where: any): Promise; /** * Finds entity that matches given id. * * @deprecated use `findOneBy` method instead in conjunction with `In` operator, for example: * * .findOneBy({ * id: 1 // where "id" is your primary column name * }) */ findOneById(entityClassOrName: EntityTarget, id: string | number | Date | ObjectId): 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. */ 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. */ 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. */ 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. */ 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. */ createEntityCursor(entityClassOrName: EntityTarget, query?: ObjectLiteral): FindCursor; /** * Execute an aggregation framework pipeline against the collection. */ 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. */ aggregateEntity(entityClassOrName: EntityTarget, pipeline: Document[], options?: AggregateOptions): AggregationCursor; /** * Perform a bulkWrite operation without a fluent API. */ bulkWrite(entityClassOrName: EntityTarget, operations: AnyBulkWriteOperation[], options?: BulkWriteOptions): Promise; /** * Count number of matching documents in the db to a query. */ count(entityClassOrName: EntityTarget, query?: Filter, options?: CountOptions): Promise; /** * Count number of matching documents in the db to a query. */ countDocuments(entityClassOrName: EntityTarget, query?: Filter, options?: CountDocumentsOptions): Promise; /** * Count number of matching documents in the db to a query. */ countBy(entityClassOrName: EntityTarget, query?: ObjectLiteral, options?: CountOptions): Promise; /** * Creates an index on the db and collection. */ 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/. */ createCollectionIndexes(entityClassOrName: EntityTarget, indexSpecs: IndexDescription[]): Promise; /** * Delete multiple documents on MongoDB. */ deleteMany(entityClassOrName: EntityTarget, query: Filter, options?: DeleteOptions): Promise; /** * Delete a document on MongoDB. */ 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. */ distinct(entityClassOrName: EntityTarget, key: string, query: Filter, options?: CommandOperationOptions): Promise; /** * Drops an index from this collection. */ dropCollectionIndex(entityClassOrName: EntityTarget, indexName: string, options?: CommandOperationOptions): Promise; /** * Drops all indexes from the collection. */ dropCollectionIndexes(entityClassOrName: EntityTarget): Promise; /** * Find a document and delete it in one atomic operation, requires a write lock for the duration of the operation. */ 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. */ 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. */ findOneAndUpdate(entityClassOrName: EntityTarget, query: Filter, update: UpdateFilter, options?: FindOneAndUpdateOptions): Promise; /** * Retrieve all the indexes on the collection. */ collectionIndexes(entityClassOrName: EntityTarget): Promise; /** * Retrieve all the indexes on the collection. */ collectionIndexExists(entityClassOrName: EntityTarget, indexes: string | string[]): Promise; /** * Retrieves this collections index info. */ 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. */ 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. */ initializeUnorderedBulkOp(entityClassOrName: EntityTarget, options?: BulkWriteOptions): UnorderedBulkOperation; /** * Inserts an array of documents into MongoDB. */ insertMany(entityClassOrName: EntityTarget, docs: OptionalId[], options?: BulkWriteOptions): Promise; /** * Inserts a single document into MongoDB. */ insertOne(entityClassOrName: EntityTarget, doc: OptionalId, options?: InsertOneOptions): Promise; /** * Returns if the collection is a capped collection. */ isCapped(entityClassOrName: EntityTarget): Promise; /** * Get the list of all indexes information for the collection. */ 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. */ rename(entityClassOrName: EntityTarget, newName: string, options?: RenameOptions): Promise>; /** * Replace a document on MongoDB. */ replaceOne(entityClassOrName: EntityTarget, query: Filter, doc: Document, options?: ReplaceOptions): Promise; /** * Get all the collection statistics. */ stats(entityClassOrName: EntityTarget, options?: CollStatsOptions): Promise; watch(entityClassOrName: EntityTarget, pipeline?: Document[], options?: ChangeStreamOptions): ChangeStream; /** * Update multiple documents on MongoDB. */ updateMany(entityClassOrName: EntityTarget, query: Filter, update: UpdateFilter, options?: UpdateOptions): Promise; /** * Update a single document on MongoDB. */ updateOne(entityClassOrName: EntityTarget, query: Filter, update: UpdateFilter, options?: UpdateOptions): Promise; /** * Converts FindManyOptions to mongodb query. */ protected convertFindManyOptionsOrConditionsToMongodbQuery(optionsOrConditions: MongoFindManyOptions | Partial | FilterOperators | any[] | undefined): ObjectLiteral | undefined; /** * Converts FindOneOptions to mongodb query. */ protected convertFindOneOptionsOrConditionsToMongodbQuery(optionsOrConditions: MongoFindOneOptions | Partial | undefined): ObjectLiteral | undefined; /** * Converts FindOptions into mongodb order by criteria. */ protected convertFindOptionsOrderToOrderCriteria(order: ObjectLiteral): ObjectLiteral; /** * Converts FindOptions into mongodb select by criteria. */ protected convertFindOptionsSelectToProjectCriteria(selects: FindOptionsSelect | FindOptionsSelectByString): any; /** * Ensures given id is an id for query. */ protected convertMixedCriteria(metadata: EntityMetadata, idMap: any): ObjectLiteral; /** * Overrides cursor's toArray and next methods to convert results to entity automatically. */ 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. */ 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. */ executeFindAndCount(entityClassOrName: EntityTarget, optionsOrConditions?: MongoFindManyOptions | Partial): Promise<[Entity[], number]>; }