UNPKG

16.8 kBTypeScriptView Raw
1import { Connection } from "../connection/Connection";
2import { EntityManager } from "./EntityManager";
3import { ObjectType } from "../common/ObjectType";
4import { AggregationCursor, BulkWriteOpResultObject, ChangeStream, ChangeStreamOptions, Code, Collection, CollectionAggregationOptions, CollectionBulkWriteOptions, CollectionInsertManyOptions, CollectionInsertOneOptions, CollectionOptions, CollStats, CommandCursor, Cursor, DeleteWriteOpResultObject, FindAndModifyWriteOpResultObject, FindOneAndReplaceOption, GeoHaystackSearchOptions, GeoNearOptions, InsertOneWriteOpResult, InsertWriteOpResult, MapReduceOptions, MongoCountPreferences, MongodbIndexOptions, ObjectID, OrderedBulkOperation, ParallelCollectionScanOptions, ReadPreference, ReplaceOneOptions, UnorderedBulkOperation, UpdateWriteOpResult } from "../driver/mongodb/typings";
5import { ObjectLiteral } from "../common/ObjectLiteral";
6import { MongoQueryRunner } from "../driver/mongodb/MongoQueryRunner";
7import { FindManyOptions } from "../find-options/FindManyOptions";
8import { FindOneOptions } from "../find-options/FindOneOptions";
9import { DeepPartial } from "../common/DeepPartial";
10import { QueryDeepPartialEntity } from "../query-builder/QueryPartialEntity";
11import { InsertResult } from "../query-builder/result/InsertResult";
12import { UpdateResult } from "../query-builder/result/UpdateResult";
13import { DeleteResult } from "../query-builder/result/DeleteResult";
14import { EntityMetadata } from "../metadata/EntityMetadata";
15import { EntitySchema, FindConditions } from "../index";
16/**
17 * Entity manager supposed to work with any entity, automatically find its repository and call its methods,
18 * whatever entity type are you passing.
19 *
20 * This implementation is used for MongoDB driver which has some specifics in its EntityManager.
21 */
22export declare class MongoEntityManager extends EntityManager {
23 constructor(connection: Connection);
24 /**
25 * Gets query runner used to execute queries.
26 */
27 readonly queryRunner: MongoQueryRunner;
28 /**
29 * Finds entities that match given find options or conditions.
30 */
31 find<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, optionsOrConditions?: FindManyOptions<Entity> | Partial<Entity>): Promise<Entity[]>;
32 /**
33 * Finds entities that match given find options or conditions.
34 * Also counts all entities that match given conditions,
35 * but ignores pagination settings (from and take options).
36 */
37 findAndCount<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, optionsOrConditions?: FindManyOptions<Entity> | Partial<Entity>): Promise<[Entity[], number]>;
38 /**
39 * Finds entities by ids.
40 * Optionally find options can be applied.
41 */
42 findByIds<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, ids: any[], optionsOrConditions?: FindManyOptions<Entity> | Partial<Entity>): Promise<Entity[]>;
43 /**
44 * Finds first entity that matches given conditions and/or find options.
45 */
46 findOne<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, optionsOrConditions?: string | string[] | number | number[] | Date | Date[] | ObjectID | ObjectID[] | FindOneOptions<Entity> | DeepPartial<Entity>, maybeOptions?: FindOneOptions<Entity>): Promise<Entity | undefined>;
47 /**
48 * Inserts a given entity into the database.
49 * Unlike save method executes a primitive operation without cascades, relations and other operations included.
50 * Executes fast and efficient INSERT query.
51 * Does not check if entity exist in the database, so query will fail if duplicate entity is being inserted.
52 * You can execute bulk inserts using this method.
53 */
54 insert<Entity>(target: ObjectType<Entity> | EntitySchema<Entity> | string, entity: QueryDeepPartialEntity<Entity> | QueryDeepPartialEntity<Entity>[]): Promise<InsertResult>;
55 /**
56 * Updates entity partially. Entity can be found by a given conditions.
57 * Unlike save method executes a primitive operation without cascades, relations and other operations included.
58 * Executes fast and efficient UPDATE query.
59 * Does not check if entity exist in the database.
60 */
61 update<Entity>(target: ObjectType<Entity> | EntitySchema<Entity> | string, criteria: string | string[] | number | number[] | Date | Date[] | ObjectID | ObjectID[] | FindConditions<Entity>, partialEntity: QueryDeepPartialEntity<Entity>): Promise<UpdateResult>;
62 /**
63 * Deletes entities by a given conditions.
64 * Unlike save method executes a primitive operation without cascades, relations and other operations included.
65 * Executes fast and efficient DELETE query.
66 * Does not check if entity exist in the database.
67 */
68 delete<Entity>(target: ObjectType<Entity> | EntitySchema<Entity> | string, criteria: string | string[] | number | number[] | Date | Date[] | ObjectID | ObjectID[] | FindConditions<Entity>): Promise<DeleteResult>;
69 /**
70 * Creates a cursor for a query that can be used to iterate over results from MongoDB.
71 */
72 createCursor<Entity, T = any>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, query?: ObjectLiteral): Cursor<T>;
73 /**
74 * Creates a cursor for a query that can be used to iterate over results from MongoDB.
75 * This returns modified version of cursor that transforms each result into Entity model.
76 */
77 createEntityCursor<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, query?: ObjectLiteral): Cursor<Entity>;
78 /**
79 * Execute an aggregation framework pipeline against the collection.
80 */
81 aggregate<Entity, R = any>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, pipeline: ObjectLiteral[], options?: CollectionAggregationOptions): AggregationCursor<R>;
82 /**
83 * Execute an aggregation framework pipeline against the collection.
84 * This returns modified version of cursor that transforms each result into Entity model.
85 */
86 aggregateEntity<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, pipeline: ObjectLiteral[], options?: CollectionAggregationOptions): AggregationCursor<Entity>;
87 /**
88 * Perform a bulkWrite operation without a fluent API.
89 */
90 bulkWrite<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, operations: ObjectLiteral[], options?: CollectionBulkWriteOptions): Promise<BulkWriteOpResultObject>;
91 /**
92 * Count number of matching documents in the db to a query.
93 */
94 count<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, query?: ObjectLiteral, options?: MongoCountPreferences): Promise<number>;
95 /**
96 * Creates an index on the db and collection.
97 */
98 createCollectionIndex<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, fieldOrSpec: string | any, options?: MongodbIndexOptions): Promise<string>;
99 /**
100 * Creates multiple indexes in the collection, this method is only supported for MongoDB 2.6 or higher.
101 * Earlier version of MongoDB will throw a command not supported error.
102 * Index specifications are defined at http://docs.mongodb.org/manual/reference/command/createIndexes/.
103 */
104 createCollectionIndexes<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, indexSpecs: ObjectLiteral[]): Promise<void>;
105 /**
106 * Delete multiple documents on MongoDB.
107 */
108 deleteMany<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, query: ObjectLiteral, options?: CollectionOptions): Promise<DeleteWriteOpResultObject>;
109 /**
110 * Delete a document on MongoDB.
111 */
112 deleteOne<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, query: ObjectLiteral, options?: CollectionOptions): Promise<DeleteWriteOpResultObject>;
113 /**
114 * The distinct command returns returns a list of distinct values for the given key across a collection.
115 */
116 distinct<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, key: string, query: ObjectLiteral, options?: {
117 readPreference?: ReadPreference | string;
118 }): Promise<any>;
119 /**
120 * Drops an index from this collection.
121 */
122 dropCollectionIndex<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, indexName: string, options?: CollectionOptions): Promise<any>;
123 /**
124 * Drops all indexes from the collection.
125 */
126 dropCollectionIndexes<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string): Promise<any>;
127 /**
128 * Find a document and delete it in one atomic operation, requires a write lock for the duration of the operation.
129 */
130 findOneAndDelete<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, query: ObjectLiteral, options?: {
131 projection?: Object;
132 sort?: Object;
133 maxTimeMS?: number;
134 }): Promise<FindAndModifyWriteOpResultObject>;
135 /**
136 * Find a document and replace it in one atomic operation, requires a write lock for the duration of the operation.
137 */
138 findOneAndReplace<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, query: ObjectLiteral, replacement: Object, options?: FindOneAndReplaceOption): Promise<FindAndModifyWriteOpResultObject>;
139 /**
140 * Find a document and update it in one atomic operation, requires a write lock for the duration of the operation.
141 */
142 findOneAndUpdate<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, query: ObjectLiteral, update: Object, options?: FindOneAndReplaceOption): Promise<FindAndModifyWriteOpResultObject>;
143 /**
144 * Execute a geo search using a geo haystack index on a collection.
145 */
146 geoHaystackSearch<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, x: number, y: number, options?: GeoHaystackSearchOptions): Promise<any>;
147 /**
148 * Execute the geoNear command to search for items in the collection.
149 */
150 geoNear<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, x: number, y: number, options?: GeoNearOptions): Promise<any>;
151 /**
152 * Run a group command across a collection.
153 */
154 group<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, keys: Object | Array<any> | Function | Code, condition: Object, initial: Object, reduce: Function | Code, finalize: Function | Code, command: boolean, options?: {
155 readPreference?: ReadPreference | string;
156 }): Promise<any>;
157 /**
158 * Retrieve all the indexes on the collection.
159 */
160 collectionIndexes<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string): Promise<any>;
161 /**
162 * Retrieve all the indexes on the collection.
163 */
164 collectionIndexExists<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, indexes: string | string[]): Promise<boolean>;
165 /**
166 * Retrieves this collections index info.
167 */
168 collectionIndexInformation<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, options?: {
169 full: boolean;
170 }): Promise<any>;
171 /**
172 * 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.
173 */
174 initializeOrderedBulkOp<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, options?: CollectionOptions): OrderedBulkOperation;
175 /**
176 * Initiate a Out of order batch write operation. All operations will be buffered into insert/update/remove commands executed out of order.
177 */
178 initializeUnorderedBulkOp<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, options?: CollectionOptions): UnorderedBulkOperation;
179 /**
180 * Inserts an array of documents into MongoDB.
181 */
182 insertMany<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, docs: ObjectLiteral[], options?: CollectionInsertManyOptions): Promise<InsertWriteOpResult>;
183 /**
184 * Inserts a single document into MongoDB.
185 */
186 insertOne<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, doc: ObjectLiteral, options?: CollectionInsertOneOptions): Promise<InsertOneWriteOpResult>;
187 /**
188 * Returns if the collection is a capped collection.
189 */
190 isCapped<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string): Promise<any>;
191 /**
192 * Get the list of all indexes information for the collection.
193 */
194 listCollectionIndexes<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, options?: {
195 batchSize?: number;
196 readPreference?: ReadPreference | string;
197 }): CommandCursor;
198 /**
199 * Run Map Reduce across a collection. Be aware that the inline option for out will return an array of results not a collection.
200 */
201 mapReduce<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, map: Function | string, reduce: Function | string, options?: MapReduceOptions): Promise<any>;
202 /**
203 * Return N number of parallel cursors for a collection allowing parallel reading of entire collection.
204 * There are no ordering guarantees for returned results.
205 */
206 parallelCollectionScan<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, options?: ParallelCollectionScanOptions): Promise<Cursor<Entity>[]>;
207 /**
208 * 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.
209 */
210 reIndex<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string): Promise<any>;
211 /**
212 * 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.
213 */
214 rename<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, newName: string, options?: {
215 dropTarget?: boolean;
216 }): Promise<Collection<any>>;
217 /**
218 * Replace a document on MongoDB.
219 */
220 replaceOne<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, query: ObjectLiteral, doc: ObjectLiteral, options?: ReplaceOneOptions): Promise<UpdateWriteOpResult>;
221 /**
222 * Get all the collection statistics.
223 */
224 stats<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, options?: {
225 scale: number;
226 }): Promise<CollStats>;
227 watch<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, pipeline?: Object[], options?: ChangeStreamOptions): ChangeStream;
228 /**
229 * Update multiple documents on MongoDB.
230 */
231 updateMany<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, query: ObjectLiteral, update: ObjectLiteral, options?: {
232 upsert?: boolean;
233 w?: any;
234 wtimeout?: number;
235 j?: boolean;
236 }): Promise<UpdateWriteOpResult>;
237 /**
238 * Update a single document on MongoDB.
239 */
240 updateOne<Entity>(entityClassOrName: ObjectType<Entity> | EntitySchema<Entity> | string, query: ObjectLiteral, update: ObjectLiteral, options?: ReplaceOneOptions): Promise<UpdateWriteOpResult>;
241 /**
242 * Converts FindManyOptions to mongodb query.
243 */
244 protected convertFindManyOptionsOrConditionsToMongodbQuery<Entity>(optionsOrConditions: FindManyOptions<Entity> | Partial<Entity> | undefined): ObjectLiteral | undefined;
245 /**
246 * Converts FindOneOptions to mongodb query.
247 */
248 protected convertFindOneOptionsOrConditionsToMongodbQuery<Entity>(optionsOrConditions: FindOneOptions<Entity> | Partial<Entity> | undefined): ObjectLiteral | undefined;
249 /**
250 * Converts FindOptions into mongodb order by criteria.
251 */
252 protected convertFindOptionsOrderToOrderCriteria(order: ObjectLiteral): ObjectLiteral;
253 /**
254 * Converts FindOptions into mongodb select by criteria.
255 */
256 protected convertFindOptionsSelectToProjectCriteria(selects: (keyof any)[]): any;
257 /**
258 * Ensures given id is an id for query.
259 */
260 protected convertMixedCriteria(metadata: EntityMetadata, idMap: any): ObjectLiteral;
261 /**
262 * Overrides cursor's toArray and next methods to convert results to entity automatically.
263 */
264 protected applyEntityTransformationToCursor<Entity>(metadata: EntityMetadata, cursor: Cursor<Entity> | AggregationCursor<Entity>): void;
265}