• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

typeorm / typeorm / 19549987525

20 Nov 2025 08:11PM UTC coverage: 80.769% (+4.3%) from 76.433%
19549987525

push

github

web-flow
ci: run tests on commits to master and next (#11783)

Co-authored-by: Oleg "OSA413" Sokolov <OSA413@users.noreply.github.com>

26500 of 32174 branches covered (82.36%)

Branch coverage included in aggregate %.

91252 of 113615 relevant lines covered (80.32%)

88980.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.52
/src/driver/mongodb/MongoQueryRunner.ts
1
import { QueryRunner } from "../../query-runner/QueryRunner"
26✔
2
import { TableColumn } from "../../schema-builder/table/TableColumn"
26✔
3
import { Table } from "../../schema-builder/table/Table"
26✔
4
import { TableForeignKey } from "../../schema-builder/table/TableForeignKey"
26✔
5
import { TableIndex } from "../../schema-builder/table/TableIndex"
26✔
6
import { View } from "../../schema-builder/view/View"
26✔
7
// import {Connection} from "../../connection/Connection";
26✔
8
import { ReadStream } from "../../platform/PlatformTools"
26✔
9
import { MongoEntityManager } from "../../entity-manager/MongoEntityManager"
26✔
10
import { SqlInMemory } from "../SqlInMemory"
26✔
11
import { TableUnique } from "../../schema-builder/table/TableUnique"
26✔
12
import { Broadcaster } from "../../subscriber/Broadcaster"
26✔
13
import { TableCheck } from "../../schema-builder/table/TableCheck"
26✔
14
import { TableExclusion } from "../../schema-builder/table/TableExclusion"
26✔
15
import { TypeORMError } from "../../error"
26✔
16

26✔
17
import {
26✔
18
    BulkWriteResult,
26✔
19
    AggregationCursor,
26✔
20
    MongoClient,
26✔
21
    Collection,
26✔
22
    FindCursor,
26✔
23
    Document,
26✔
24
    AggregateOptions,
26✔
25
    AnyBulkWriteOperation,
26✔
26
    BulkWriteOptions,
26✔
27
    Filter,
26✔
28
    CountOptions,
26✔
29
    CountDocumentsOptions,
26✔
30
    IndexSpecification,
26✔
31
    CreateIndexesOptions,
26✔
32
    IndexDescription,
26✔
33
    DeleteResult,
26✔
34
    DeleteOptions,
26✔
35
    CommandOperationOptions,
26✔
36
    FindOneAndDeleteOptions,
26✔
37
    FindOneAndReplaceOptions,
26✔
38
    UpdateFilter,
26✔
39
    FindOneAndUpdateOptions,
26✔
40
    RenameOptions,
26✔
41
    ReplaceOptions,
26✔
42
    UpdateResult,
26✔
43
    CollStats,
26✔
44
    CollStatsOptions,
26✔
45
    ChangeStreamOptions,
26✔
46
    ChangeStream,
26✔
47
    UpdateOptions,
26✔
48
    ListIndexesOptions,
26✔
49
    ListIndexesCursor,
26✔
50
    OptionalId,
26✔
51
    InsertOneOptions,
26✔
52
    InsertOneResult,
26✔
53
    InsertManyResult,
26✔
54
    UnorderedBulkOperation,
26✔
55
    OrderedBulkOperation,
26✔
56
    IndexInformationOptions,
26✔
57
} from "../../driver/mongodb/typings"
26✔
58
import { DataSource } from "../../data-source/DataSource"
26✔
59
import { ReplicationMode } from "../types/ReplicationMode"
26✔
60

26✔
61
/**
26✔
62
 * Runs queries on a single MongoDB connection.
26✔
63
 */
26✔
64
export class MongoQueryRunner implements QueryRunner {
26✔
65
    // -------------------------------------------------------------------------
26✔
66
    // Public Implemented Properties
26✔
67
    // -------------------------------------------------------------------------
26✔
68

26✔
69
    /**
26✔
70
     * Connection used by this query runner.
26✔
71
     */
26✔
72
    connection: DataSource
26✔
73

26✔
74
    /**
26✔
75
     * Broadcaster used on this query runner to broadcast entity events.
26✔
76
     */
26✔
77
    broadcaster: Broadcaster
26✔
78

26✔
79
    /**
26✔
80
     * Entity manager working only with current query runner.
26✔
81
     */
26✔
82
    manager: MongoEntityManager
26✔
83

26✔
84
    /**
26✔
85
     * Indicates if connection for this query runner is released.
26✔
86
     * Once its released, query runner cannot run queries anymore.
26✔
87
     * Always false for mongodb since mongodb has a single query executor instance.
26✔
88
     */
26✔
89
    isReleased = false
26✔
90

26✔
91
    /**
26✔
92
     * Indicates if transaction is active in this query executor.
26✔
93
     * Always false for mongodb since mongodb does not support transactions.
26✔
94
     */
26✔
95
    isTransactionActive = false
26✔
96

26✔
97
    /**
26✔
98
     * Stores temporarily user data.
26✔
99
     * Useful for sharing data with subscribers.
26✔
100
     */
26✔
101
    data = {}
26✔
102

26✔
103
    /**
26✔
104
     * All synchronized tables in the database.
26✔
105
     */
26✔
106
    loadedTables: Table[]
26✔
107

26✔
108
    /**
26✔
109
     * All synchronized views in the database.
26✔
110
     */
26✔
111
    loadedViews: View[]
26✔
112

26✔
113
    /**
26✔
114
     * Real database connection from a connection pool used to perform queries.
26✔
115
     */
26✔
116
    databaseConnection: MongoClient
26✔
117

26✔
118
    // -------------------------------------------------------------------------
26✔
119
    // Constructor
26✔
120
    // -------------------------------------------------------------------------
26✔
121

26✔
122
    constructor(connection: DataSource, databaseConnection: MongoClient) {
26✔
123
        this.connection = connection
136✔
124
        this.databaseConnection = databaseConnection
136✔
125
        this.broadcaster = new Broadcaster(this)
136✔
126
    }
136✔
127

26✔
128
    // -------------------------------------------------------------------------
26✔
129
    // Public Methods
26✔
130
    // -------------------------------------------------------------------------
26✔
131

26✔
132
    /**
26✔
133
     * Called before migrations are run.
26✔
134
     */
26✔
135
    async beforeMigration(): Promise<void> {
26✔
136
        // Do nothing
6✔
137
    }
6✔
138

26✔
139
    /**
26✔
140
     * Called after migrations are run.
26✔
141
     */
26✔
142
    async afterMigration(): Promise<void> {
26✔
143
        // Do nothing
6✔
144
    }
6✔
145

26✔
146
    /**
26✔
147
     * Creates a cursor for a query that can be used to iterate over results from MongoDB.
26✔
148
     */
26✔
149
    cursor(collectionName: string, filter: Filter<Document>): FindCursor<any> {
26✔
150
        return this.getCollection(collectionName).find(filter || {})
204!
151
    }
204✔
152

26✔
153
    /**
26✔
154
     * Execute an aggregation framework pipeline against the collection.
26✔
155
     */
26✔
156
    aggregate(
26✔
157
        collectionName: string,
4✔
158
        pipeline: Document[],
4✔
159
        options?: AggregateOptions,
4✔
160
    ): AggregationCursor<any> {
4✔
161
        return this.getCollection(collectionName).aggregate(
4✔
162
            pipeline,
4✔
163
            options || {},
4✔
164
        )
4✔
165
    }
4✔
166

26✔
167
    /**
26✔
168
     * Perform a bulkWrite operation without a fluent API.
26✔
169
     */
26✔
170
    async bulkWrite(
26✔
171
        collectionName: string,
×
172
        operations: AnyBulkWriteOperation<Document>[],
×
173
        options?: BulkWriteOptions,
×
174
    ): Promise<BulkWriteResult> {
×
175
        return await this.getCollection(collectionName).bulkWrite(
×
176
            operations,
×
177
            options || {},
×
178
        )
×
179
    }
×
180

26✔
181
    /**
26✔
182
     * Count number of matching documents in the db to a query.
26✔
183
     */
26✔
184
    async count(
26✔
185
        collectionName: string,
32✔
186
        filter: Filter<Document>,
32✔
187
        options?: CountOptions,
32✔
188
    ): Promise<number> {
32✔
189
        return this.getCollection(collectionName).count(
32✔
190
            filter || {},
32!
191
            options || {},
32!
192
        )
32✔
193
    }
32✔
194

26✔
195
    /**
26✔
196
     * Count number of matching documents in the db to a query.
26✔
197
     */
26✔
198
    async countDocuments(
26✔
199
        collectionName: string,
×
200
        filter: Filter<Document>,
×
201
        options?: CountDocumentsOptions,
×
202
    ): Promise<any> {
×
203
        return this.getCollection(collectionName).countDocuments(
×
204
            filter || {},
×
205
            options || {},
×
206
        )
×
207
    }
×
208

26✔
209
    /**
26✔
210
     * Creates an index on the db and collection.
26✔
211
     */
26✔
212
    async createCollectionIndex(
26✔
213
        collectionName: string,
22✔
214
        indexSpec: IndexSpecification,
22✔
215
        options?: CreateIndexesOptions,
22✔
216
    ): Promise<string> {
22✔
217
        return this.getCollection(collectionName).createIndex(
22✔
218
            indexSpec,
22✔
219
            options || {},
22!
220
        )
22✔
221
    }
22✔
222

26✔
223
    /**
26✔
224
     * Creates multiple indexes in the collection, this method is only supported for MongoDB 2.6 or higher.
26✔
225
     * Earlier version of MongoDB will throw a command not supported error. Index specifications are defined at http://docs.mongodb.org/manual/reference/command/createIndexes/.
26✔
226
     */
26✔
227
    async createCollectionIndexes(
26✔
228
        collectionName: string,
×
229
        indexSpecs: IndexDescription[],
×
230
    ): Promise<string[]> {
×
231
        return this.getCollection(collectionName).createIndexes(indexSpecs)
×
232
    }
×
233

26✔
234
    /**
26✔
235
     * Delete multiple documents on MongoDB.
26✔
236
     */
26✔
237
    async deleteMany(
26✔
238
        collectionName: string,
16✔
239
        filter: Filter<Document>,
16✔
240
        options: DeleteOptions,
16✔
241
    ): Promise<DeleteResult> {
16✔
242
        return this.getCollection(collectionName).deleteMany(
16✔
243
            filter,
16✔
244
            options || {},
16!
245
        )
16✔
246
    }
16✔
247

26✔
248
    /**
26✔
249
     * Delete a document on MongoDB.
26✔
250
     */
26✔
251
    async deleteOne(
26✔
252
        collectionName: string,
×
253
        filter: Filter<Document>,
×
254
        options?: DeleteOptions,
×
255
    ): Promise<DeleteResult> {
×
256
        return this.getCollection(collectionName).deleteOne(
×
257
            filter,
×
258
            options || {},
×
259
        )
×
260
    }
×
261

26✔
262
    /**
26✔
263
     * The distinct command returns returns a list of distinct values for the given key across a collection.
26✔
264
     */
26✔
265
    async distinct(
26✔
266
        collectionName: string,
×
267
        key: any,
×
268
        filter: Filter<Document>,
×
269
        options?: CommandOperationOptions,
×
270
    ): Promise<any> {
×
271
        return this.getCollection(collectionName).distinct(
×
272
            key,
×
273
            filter,
×
274
            options || {},
×
275
        )
×
276
    }
×
277

26✔
278
    /**
26✔
279
     * Drops an index from this collection.
26✔
280
     */
26✔
281
    async dropCollectionIndex(
26✔
282
        collectionName: string,
×
283
        indexName: string,
×
284
        options?: CommandOperationOptions,
×
285
    ): Promise<Document> {
×
286
        return this.getCollection(collectionName).dropIndex(
×
287
            indexName,
×
288
            options || {},
×
289
        )
×
290
    }
×
291

26✔
292
    /**
26✔
293
     * Drops all indexes from the collection.
26✔
294
     */
26✔
295
    async dropCollectionIndexes(collectionName: string): Promise<Document> {
26✔
296
        return this.getCollection(collectionName).dropIndexes()
×
297
    }
×
298

26✔
299
    /**
26✔
300
     * Find a document and delete it in one atomic operation, requires a write lock for the duration of the operation.
26✔
301
     */
26✔
302
    async findOneAndDelete(
26✔
303
        collectionName: string,
×
304
        filter: Filter<Document>,
×
305
        options?: FindOneAndDeleteOptions,
×
306
    ): Promise<Document | null> {
×
307
        return this.getCollection(collectionName).findOneAndDelete(
×
308
            filter,
×
309
            options || {},
×
310
        )
×
311
    }
×
312

26✔
313
    /**
26✔
314
     * Find a document and replace it in one atomic operation, requires a write lock for the duration of the operation.
26✔
315
     */
26✔
316
    async findOneAndReplace(
26✔
317
        collectionName: string,
×
318
        filter: Filter<Document>,
×
319
        replacement: Document,
×
320
        options?: FindOneAndReplaceOptions,
×
321
    ): Promise<Document | null> {
×
322
        return this.getCollection(collectionName).findOneAndReplace(
×
323
            filter,
×
324
            replacement,
×
325
            options || {},
×
326
        )
×
327
    }
×
328

26✔
329
    /**
26✔
330
     * Find a document and update it in one atomic operation, requires a write lock for the duration of the operation.
26✔
331
     */
26✔
332
    async findOneAndUpdate(
26✔
333
        collectionName: string,
×
334
        filter: Filter<Document>,
×
335
        update: UpdateFilter<Document>,
×
336
        options?: FindOneAndUpdateOptions,
×
337
    ): Promise<Document | null> {
×
338
        return this.getCollection(collectionName).findOneAndUpdate(
×
339
            filter,
×
340
            update,
×
341
            options || {},
×
342
        )
×
343
    }
×
344

26✔
345
    /**
26✔
346
     * Retrieve all the indexes on the collection.
26✔
347
     */
26✔
348
    async collectionIndexes(collectionName: string): Promise<Document> {
26✔
349
        return this.getCollection(collectionName).indexes()
×
350
    }
×
351

26✔
352
    /**
26✔
353
     * Retrieve all the indexes on the collection.
26✔
354
     */
26✔
355
    async collectionIndexExists(
26✔
356
        collectionName: string,
×
357
        indexes: string | string[],
×
358
    ): Promise<boolean> {
×
359
        return this.getCollection(collectionName).indexExists(indexes)
×
360
    }
×
361

26✔
362
    /**
26✔
363
     * Retrieves this collections index info.
26✔
364
     */
26✔
365
    async collectionIndexInformation(
26✔
366
        collectionName: string,
×
367
        options?: IndexInformationOptions,
×
368
    ): Promise<any> {
×
369
        return this.getCollection(collectionName).indexInformation(
×
370
            options || {},
×
371
        )
×
372
    }
×
373

26✔
374
    /**
26✔
375
     * 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.
26✔
376
     */
26✔
377
    initializeOrderedBulkOp(
26✔
378
        collectionName: string,
×
379
        options?: BulkWriteOptions,
×
380
    ): OrderedBulkOperation {
×
381
        return this.getCollection(collectionName).initializeOrderedBulkOp(
×
382
            options,
×
383
        )
×
384
    }
×
385

26✔
386
    /**
26✔
387
     * Initiate a Out of order batch write operation. All operations will be buffered into insert/update/remove commands executed out of order.
26✔
388
     */
26✔
389
    initializeUnorderedBulkOp(
26✔
390
        collectionName: string,
×
391
        options?: BulkWriteOptions,
×
392
    ): UnorderedBulkOperation {
×
393
        return this.getCollection(collectionName).initializeUnorderedBulkOp(
×
394
            options,
×
395
        )
×
396
    }
×
397

26✔
398
    /**
26✔
399
     * Inserts an array of documents into MongoDB.
26✔
400
     */
26✔
401
    async insertMany(
26✔
402
        collectionName: string,
192✔
403
        docs: OptionalId<Document>[],
192✔
404
        options?: BulkWriteOptions,
192✔
405
    ): Promise<InsertManyResult> {
192✔
406
        return this.getCollection(collectionName).insertMany(
192✔
407
            docs,
192✔
408
            options || {},
192✔
409
        )
192✔
410
    }
192✔
411

26✔
412
    /**
26✔
413
     * Inserts a single document into MongoDB.
26✔
414
     */
26✔
415
    async insertOne(
26✔
416
        collectionName: string,
8✔
417
        doc: OptionalId<Document>,
8✔
418
        options?: InsertOneOptions,
8✔
419
    ): Promise<InsertOneResult> {
8✔
420
        return this.getCollection(collectionName).insertOne(doc, options || {})
8✔
421
    }
8✔
422

26✔
423
    /**
26✔
424
     * Returns if the collection is a capped collection.
26✔
425
     */
26✔
426
    async isCapped(collectionName: string): Promise<boolean> {
26✔
427
        return this.getCollection(collectionName).isCapped()
×
428
    }
×
429

26✔
430
    /**
26✔
431
     * Get the list of all indexes information for the collection.
26✔
432
     */
26✔
433
    listCollectionIndexes(
26✔
434
        collectionName: string,
×
435
        options?: ListIndexesOptions,
×
436
    ): ListIndexesCursor {
×
437
        return this.getCollection(collectionName).listIndexes(options)
×
438
    }
×
439

26✔
440
    /**
26✔
441
     * 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.
26✔
442
     */
26✔
443
    async rename(
26✔
444
        collectionName: string,
×
445
        newName: string,
×
446
        options?: RenameOptions,
×
447
    ): Promise<Collection<Document>> {
×
448
        return this.getCollection(collectionName).rename(newName, options || {})
×
449
    }
×
450

26✔
451
    /**
26✔
452
     * Replace a document on MongoDB.
26✔
453
     */
26✔
454
    async replaceOne(
26✔
455
        collectionName: string,
×
456
        filter: Filter<Document>,
×
457
        replacement: Document,
×
458
        options?: ReplaceOptions,
×
459
    ): Promise<Document | UpdateResult> {
×
460
        return this.getCollection(collectionName).replaceOne(
×
461
            filter,
×
462
            replacement,
×
463
            options || {},
×
464
        )
×
465
    }
×
466

26✔
467
    /**
26✔
468
     * Get all the collection statistics.
26✔
469
     */
26✔
470
    async stats(
26✔
471
        collectionName: string,
×
472
        options?: CollStatsOptions,
×
473
    ): Promise<CollStats> {
×
474
        return this.getCollection(collectionName).stats(options || {})
×
475
    }
×
476

26✔
477
    /**
26✔
478
     * Watching new changes as stream.
26✔
479
     */
26✔
480
    watch(
26✔
481
        collectionName: string,
×
482
        pipeline?: Document[],
×
483
        options?: ChangeStreamOptions,
×
484
    ): ChangeStream {
×
485
        return this.getCollection(collectionName).watch(pipeline, options)
×
486
    }
×
487

26✔
488
    /**
26✔
489
     * Update multiple documents on MongoDB.
26✔
490
     */
26✔
491
    async updateMany(
26✔
492
        collectionName: string,
32✔
493
        filter: Filter<Document>,
32✔
494
        update: UpdateFilter<Document>,
32✔
495
        options?: UpdateOptions,
32✔
496
    ): Promise<Document | UpdateResult> {
32✔
497
        return this.getCollection(collectionName).updateMany(
32✔
498
            filter,
32✔
499
            update,
32✔
500
            options || {},
32✔
501
        )
32✔
502
    }
32✔
503

26✔
504
    /**
26✔
505
     * Update a single document on MongoDB.
26✔
506
     */
26✔
507
    async updateOne(
26✔
508
        collectionName: string,
×
509
        filter: Filter<Document>,
×
510
        update: UpdateFilter<Document>,
×
511
        options?: UpdateOptions,
×
512
    ): Promise<Document | UpdateResult> {
×
513
        return await this.getCollection(collectionName).updateOne(
×
514
            filter,
×
515
            update,
×
516
            options || {},
×
517
        )
×
518
    }
×
519

26✔
520
    // -------------------------------------------------------------------------
26✔
521
    // Public Implemented Methods (from QueryRunner)
26✔
522
    // -------------------------------------------------------------------------
26✔
523

26✔
524
    /**
26✔
525
     * Removes all collections from the currently connected database.
26✔
526
     * Be careful with using this method and avoid using it in production or migrations
26✔
527
     * (because it can clear all your database).
26✔
528
     */
26✔
529
    async clearDatabase(): Promise<void> {
26✔
530
        await this.databaseConnection
150✔
531
            .db(this.connection.driver.database!)
150✔
532
            .dropDatabase()
150✔
533
    }
150✔
534

26✔
535
    /**
26✔
536
     * For MongoDB database we don't create a connection because its single connection already created by a driver.
26✔
537
     */
26✔
538
    async connect(): Promise<any> {}
26✔
539

26✔
540
    /**
26✔
541
     * For MongoDB database we don't release the connection because it is a single connection.
26✔
542
     */
26✔
543
    async release(): Promise<void> {
26✔
544
        // the mongodb driver does not support releasing connection, so simply don't do anything here
436✔
545
    }
436✔
546

26✔
547
    /**
26✔
548
     * Starts transaction.
26✔
549
     */
26✔
550
    async startTransaction(): Promise<void> {
26✔
551
        // transactions are not supported by mongodb driver, so simply don't do anything here
6✔
552
    }
6✔
553

26✔
554
    /**
26✔
555
     * Commits transaction.
26✔
556
     */
26✔
557
    async commitTransaction(): Promise<void> {
26✔
558
        // transactions are not supported by mongodb driver, so simply don't do anything here
6✔
559
    }
6✔
560

26✔
561
    /**
26✔
562
     * Rollbacks transaction.
26✔
563
     */
26✔
564
    async rollbackTransaction(): Promise<void> {
26✔
565
        // transactions are not supported by mongodb driver, so simply don't do anything here
×
566
    }
×
567

26✔
568
    /**
26✔
569
     * Executes a given SQL query.
26✔
570
     */
26✔
571
    query(query: string, parameters?: any[]): Promise<any> {
26✔
572
        throw new TypeORMError(
×
573
            `Executing SQL query is not supported by MongoDB driver.`,
×
574
        )
×
575
    }
×
576

26✔
577
    /**
26✔
578
     * Unsupported - Executing SQL query is not supported by MongoDB driver.
26✔
579
     */
26✔
580
    async sql(
26✔
581
        strings: TemplateStringsArray,
×
582
        ...values: unknown[]
×
583
    ): Promise<any> {
×
584
        throw new TypeORMError(
×
585
            `Executing SQL query is not supported by MongoDB driver.`,
×
586
        )
×
587
    }
×
588

26✔
589
    /**
26✔
590
     * Returns raw data stream.
26✔
591
     */
26✔
592
    stream(
26✔
593
        query: string,
×
594
        parameters?: any[],
×
595
        onEnd?: Function,
×
596
        onError?: Function,
×
597
    ): Promise<ReadStream> {
×
598
        throw new TypeORMError(
×
599
            `Stream is not supported by MongoDB driver. Use watch instead.`,
×
600
        )
×
601
    }
×
602

26✔
603
    /**
26✔
604
     * Insert a new row with given values into the given table.
26✔
605
     * Returns value of inserted object id.
26✔
606

26✔
607
    async insert(collectionName: string, keyValues: ObjectLiteral): Promise<any> { // todo: fix any
26✔
608
        const results = await this.databaseConnection
26✔
609
            .collection(collectionName)
26✔
610
            .insertOne(keyValues);
26✔
611
        const generatedMap = this.connection.getMetadata(collectionName).objectIdColumn!.createValueMap(results.insertedId);
26✔
612
        return {
26✔
613
            result: results,
26✔
614
            generatedMap: generatedMap
26✔
615
        };
26✔
616
    }*/
26✔
617

26✔
618
    /**
26✔
619
     * Updates rows that match given conditions in the given table.
26✔
620

26✔
621
    async update(collectionName: string, valuesMap: ObjectLiteral, conditions: ObjectLiteral): Promise<any> { // todo: fix any
26✔
622
        await this.databaseConnection
26✔
623
            .collection(collectionName)
26✔
624
            .updateOne(conditions, valuesMap);
26✔
625
    }*/
26✔
626

26✔
627
    /**
26✔
628
     * Deletes from the given table by a given conditions.
26✔
629

26✔
630
    async delete(collectionName: string, conditions: ObjectLiteral|ObjectLiteral[]|string, maybeParameters?: any[]): Promise<any> { // todo: fix any
26✔
631
        if (typeof conditions === "string")
26✔
632
            throw new TypeORMError(`String condition is not supported by MongoDB driver.`);
26✔
633

26✔
634
        await this.databaseConnection
26✔
635
            .collection(collectionName)
26✔
636
            .deleteOne(conditions);
26✔
637
    }*/
26✔
638

26✔
639
    /**
26✔
640
     * Returns all available database names including system databases.
26✔
641
     */
26✔
642
    async getDatabases(): Promise<string[]> {
26✔
643
        throw new TypeORMError(
×
644
            `Schema update queries are not supported by MongoDB driver.`,
×
645
        )
×
646
    }
×
647

26✔
648
    /**
26✔
649
     * Returns all available schema names including system schemas.
26✔
650
     * If database parameter specified, returns schemas of that database.
26✔
651
     */
26✔
652
    async getSchemas(database?: string): Promise<string[]> {
26✔
653
        throw new TypeORMError(
×
654
            `Schema update queries are not supported by MongoDB driver.`,
×
655
        )
×
656
    }
×
657

26✔
658
    /**
26✔
659
     * Loads given table's data from the database.
26✔
660
     */
26✔
661
    async getTable(collectionName: string): Promise<Table | undefined> {
26✔
662
        throw new TypeORMError(
×
663
            `Schema update queries are not supported by MongoDB driver.`,
×
664
        )
×
665
    }
×
666

26✔
667
    /**
26✔
668
     * Loads all tables (with given names) from the database and creates a Table from them.
26✔
669
     */
26✔
670
    async getTables(collectionNames: string[]): Promise<Table[]> {
26✔
671
        throw new TypeORMError(
×
672
            `Schema update queries are not supported by MongoDB driver.`,
×
673
        )
×
674
    }
×
675

26✔
676
    /**
26✔
677
     * Loads given views's data from the database.
26✔
678
     */
26✔
679
    async getView(collectionName: string): Promise<View | undefined> {
26✔
680
        throw new TypeORMError(
×
681
            `Schema update queries are not supported by MongoDB driver.`,
×
682
        )
×
683
    }
×
684

26✔
685
    /**
26✔
686
     * Loads all views (with given names) from the database and creates a Table from them.
26✔
687
     */
26✔
688
    async getViews(collectionNames: string[]): Promise<View[]> {
26✔
689
        throw new TypeORMError(
×
690
            `Schema update queries are not supported by MongoDB driver.`,
×
691
        )
×
692
    }
×
693

26✔
694
    getReplicationMode(): ReplicationMode {
26✔
695
        return "master"
×
696
    }
×
697

26✔
698
    /**
26✔
699
     * Checks if database with the given name exist.
26✔
700
     */
26✔
701
    async hasDatabase(database: string): Promise<boolean> {
26✔
702
        throw new TypeORMError(
×
703
            `Check database queries are not supported by MongoDB driver.`,
×
704
        )
×
705
    }
×
706

26✔
707
    /**
26✔
708
     * Loads currently using database
26✔
709
     */
26✔
710
    async getCurrentDatabase(): Promise<undefined> {
26✔
711
        throw new TypeORMError(
×
712
            `Check database queries are not supported by MongoDB driver.`,
×
713
        )
×
714
    }
×
715

26✔
716
    /**
26✔
717
     * Checks if schema with the given name exist.
26✔
718
     */
26✔
719
    async hasSchema(schema: string): Promise<boolean> {
26✔
720
        throw new TypeORMError(
×
721
            `Check schema queries are not supported by MongoDB driver.`,
×
722
        )
×
723
    }
×
724

26✔
725
    /**
26✔
726
     * Loads currently using database schema
26✔
727
     */
26✔
728
    async getCurrentSchema(): Promise<undefined> {
26✔
729
        throw new TypeORMError(
×
730
            `Check schema queries are not supported by MongoDB driver.`,
×
731
        )
×
732
    }
×
733

26✔
734
    /**
26✔
735
     * Checks if table with the given name exist in the database.
26✔
736
     */
26✔
737
    async hasTable(collectionName: string): Promise<boolean> {
26✔
738
        throw new TypeORMError(
×
739
            `Check schema queries are not supported by MongoDB driver.`,
×
740
        )
×
741
    }
×
742

26✔
743
    /**
26✔
744
     * Checks if column with the given name exist in the given table.
26✔
745
     */
26✔
746
    async hasColumn(
26✔
747
        tableOrName: Table | string,
×
748
        columnName: string,
×
749
    ): Promise<boolean> {
×
750
        throw new TypeORMError(
×
751
            `Schema update queries are not supported by MongoDB driver.`,
×
752
        )
×
753
    }
×
754

26✔
755
    /**
26✔
756
     * Creates a database if it's not created.
26✔
757
     */
26✔
758
    async createDatabase(database: string): Promise<void> {
26✔
759
        throw new TypeORMError(
×
760
            `Database create queries are not supported by MongoDB driver.`,
×
761
        )
×
762
    }
×
763

26✔
764
    /**
26✔
765
     * Drops database.
26✔
766
     */
26✔
767
    async dropDatabase(database: string, ifExist?: boolean): Promise<void> {
26✔
768
        throw new TypeORMError(
×
769
            `Database drop queries are not supported by MongoDB driver.`,
×
770
        )
×
771
    }
×
772

26✔
773
    /**
26✔
774
     * Creates a new table schema.
26✔
775
     */
26✔
776
    async createSchema(
26✔
777
        schemaPath: string,
×
778
        ifNotExist?: boolean,
×
779
    ): Promise<void> {
×
780
        throw new TypeORMError(
×
781
            `Schema create queries are not supported by MongoDB driver.`,
×
782
        )
×
783
    }
×
784

26✔
785
    /**
26✔
786
     * Drops table schema.
26✔
787
     */
26✔
788
    async dropSchema(schemaPath: string, ifExist?: boolean): Promise<void> {
26✔
789
        throw new TypeORMError(
×
790
            `Schema drop queries are not supported by MongoDB driver.`,
×
791
        )
×
792
    }
×
793

26✔
794
    /**
26✔
795
     * Creates a new table from the given table and columns inside it.
26✔
796
     */
26✔
797
    async createTable(table: Table): Promise<void> {
26✔
798
        throw new TypeORMError(
×
799
            `Schema update queries are not supported by MongoDB driver.`,
×
800
        )
×
801
    }
×
802

26✔
803
    /**
26✔
804
     * Drops the table.
26✔
805
     */
26✔
806
    async dropTable(tableName: Table | string): Promise<void> {
26✔
807
        throw new TypeORMError(
×
808
            `Schema update queries are not supported by MongoDB driver.`,
×
809
        )
×
810
    }
×
811

26✔
812
    /**
26✔
813
     * Creates a new view.
26✔
814
     */
26✔
815
    async createView(view: View): Promise<void> {
26✔
816
        throw new TypeORMError(
×
817
            `Schema update queries are not supported by MongoDB driver.`,
×
818
        )
×
819
    }
×
820

26✔
821
    /**
26✔
822
     * Drops the view.
26✔
823
     */
26✔
824
    async dropView(target: View | string): Promise<void> {
26✔
825
        throw new TypeORMError(
×
826
            `Schema update queries are not supported by MongoDB driver.`,
×
827
        )
×
828
    }
×
829

26✔
830
    /**
26✔
831
     * Renames the given table.
26✔
832
     */
26✔
833
    async renameTable(
26✔
834
        oldTableOrName: Table | string,
×
835
        newTableOrName: Table | string,
×
836
    ): Promise<void> {
×
837
        throw new TypeORMError(
×
838
            `Schema update queries are not supported by MongoDB driver.`,
×
839
        )
×
840
    }
×
841

26✔
842
    /**
26✔
843
     * Creates a new column from the column in the table.
26✔
844
     */
26✔
845
    async addColumn(
26✔
846
        tableOrName: Table | string,
×
847
        column: TableColumn,
×
848
    ): Promise<void> {
×
849
        throw new TypeORMError(
×
850
            `Schema update queries are not supported by MongoDB driver.`,
×
851
        )
×
852
    }
×
853

26✔
854
    /**
26✔
855
     * Creates a new columns from the column in the table.
26✔
856
     */
26✔
857
    async addColumns(
26✔
858
        tableOrName: Table | string,
×
859
        columns: TableColumn[],
×
860
    ): Promise<void> {
×
861
        throw new TypeORMError(
×
862
            `Schema update queries are not supported by MongoDB driver.`,
×
863
        )
×
864
    }
×
865

26✔
866
    /**
26✔
867
     * Renames column in the given table.
26✔
868
     */
26✔
869
    async renameColumn(
26✔
870
        tableOrName: Table | string,
×
871
        oldTableColumnOrName: TableColumn | string,
×
872
        newTableColumnOrName: TableColumn | string,
×
873
    ): Promise<void> {
×
874
        throw new TypeORMError(
×
875
            `Schema update queries are not supported by MongoDB driver.`,
×
876
        )
×
877
    }
×
878

26✔
879
    /**
26✔
880
     * Changes a column in the table.
26✔
881
     */
26✔
882
    async changeColumn(
26✔
883
        tableOrName: Table | string,
×
884
        oldTableColumnOrName: TableColumn | string,
×
885
        newColumn: TableColumn,
×
886
    ): Promise<void> {
×
887
        throw new TypeORMError(
×
888
            `Schema update queries are not supported by MongoDB driver.`,
×
889
        )
×
890
    }
×
891

26✔
892
    /**
26✔
893
     * Changes a column in the table.
26✔
894
     */
26✔
895
    async changeColumns(
26✔
896
        tableOrName: Table | string,
×
897
        changedColumns: { newColumn: TableColumn; oldColumn: TableColumn }[],
×
898
    ): Promise<void> {
×
899
        throw new TypeORMError(
×
900
            `Schema update queries are not supported by MongoDB driver.`,
×
901
        )
×
902
    }
×
903

26✔
904
    /**
26✔
905
     * Drops column in the table.
26✔
906
     */
26✔
907
    async dropColumn(
26✔
908
        tableOrName: Table | string,
×
909
        columnOrName: TableColumn | string,
×
910
    ): Promise<void> {
×
911
        throw new TypeORMError(
×
912
            `Schema update queries are not supported by MongoDB driver.`,
×
913
        )
×
914
    }
×
915

26✔
916
    /**
26✔
917
     * Drops the columns in the table.
26✔
918
     */
26✔
919
    async dropColumns(
26✔
920
        tableOrName: Table | string,
×
921
        columns: TableColumn[] | string[],
×
922
    ): Promise<void> {
×
923
        throw new TypeORMError(
×
924
            `Schema update queries are not supported by MongoDB driver.`,
×
925
        )
×
926
    }
×
927

26✔
928
    /**
26✔
929
     * Creates a new primary key.
26✔
930
     */
26✔
931
    async createPrimaryKey(
26✔
932
        tableOrName: Table | string,
×
933
        columnNames: string[],
×
934
    ): Promise<void> {
×
935
        throw new TypeORMError(
×
936
            `Schema update queries are not supported by MongoDB driver.`,
×
937
        )
×
938
    }
×
939

26✔
940
    /**
26✔
941
     * Updates composite primary keys.
26✔
942
     */
26✔
943
    async updatePrimaryKeys(
26✔
944
        tableOrName: Table | string,
×
945
        columns: TableColumn[],
×
946
    ): Promise<void> {
×
947
        throw new TypeORMError(
×
948
            `Schema update queries are not supported by MongoDB driver.`,
×
949
        )
×
950
    }
×
951

26✔
952
    /**
26✔
953
     * Drops a primary key.
26✔
954
     */
26✔
955
    async dropPrimaryKey(tableOrName: Table | string): Promise<void> {
26✔
956
        throw new TypeORMError(
×
957
            `Schema update queries are not supported by MongoDB driver.`,
×
958
        )
×
959
    }
×
960

26✔
961
    /**
26✔
962
     * Creates a new unique constraint.
26✔
963
     */
26✔
964
    async createUniqueConstraint(
26✔
965
        tableOrName: Table | string,
×
966
        uniqueConstraint: TableUnique,
×
967
    ): Promise<void> {
×
968
        throw new TypeORMError(
×
969
            `Schema update queries are not supported by MongoDB driver.`,
×
970
        )
×
971
    }
×
972

26✔
973
    /**
26✔
974
     * Creates a new unique constraints.
26✔
975
     */
26✔
976
    async createUniqueConstraints(
26✔
977
        tableOrName: Table | string,
×
978
        uniqueConstraints: TableUnique[],
×
979
    ): Promise<void> {
×
980
        throw new TypeORMError(
×
981
            `Schema update queries are not supported by MongoDB driver.`,
×
982
        )
×
983
    }
×
984

26✔
985
    /**
26✔
986
     * Drops a unique constraint.
26✔
987
     */
26✔
988
    async dropUniqueConstraint(
26✔
989
        tableOrName: Table | string,
×
990
        uniqueOrName: TableUnique | string,
×
991
    ): Promise<void> {
×
992
        throw new TypeORMError(
×
993
            `Schema update queries are not supported by MongoDB driver.`,
×
994
        )
×
995
    }
×
996

26✔
997
    /**
26✔
998
     * Drops unique constraints.
26✔
999
     */
26✔
1000
    async dropUniqueConstraints(
26✔
1001
        tableOrName: Table | string,
×
1002
        uniqueConstraints: TableUnique[],
×
1003
    ): Promise<void> {
×
1004
        throw new TypeORMError(
×
1005
            `Schema update queries are not supported by MongoDB driver.`,
×
1006
        )
×
1007
    }
×
1008

26✔
1009
    /**
26✔
1010
     * Creates a new check constraint.
26✔
1011
     */
26✔
1012
    async createCheckConstraint(
26✔
1013
        tableOrName: Table | string,
×
1014
        checkConstraint: TableCheck,
×
1015
    ): Promise<void> {
×
1016
        throw new TypeORMError(
×
1017
            `Schema update queries are not supported by MongoDB driver.`,
×
1018
        )
×
1019
    }
×
1020

26✔
1021
    /**
26✔
1022
     * Creates a new check constraints.
26✔
1023
     */
26✔
1024
    async createCheckConstraints(
26✔
1025
        tableOrName: Table | string,
×
1026
        checkConstraints: TableCheck[],
×
1027
    ): Promise<void> {
×
1028
        throw new TypeORMError(
×
1029
            `Schema update queries are not supported by MongoDB driver.`,
×
1030
        )
×
1031
    }
×
1032

26✔
1033
    /**
26✔
1034
     * Drops check constraint.
26✔
1035
     */
26✔
1036
    async dropCheckConstraint(
26✔
1037
        tableOrName: Table | string,
×
1038
        checkOrName: TableCheck | string,
×
1039
    ): Promise<void> {
×
1040
        throw new TypeORMError(
×
1041
            `Schema update queries are not supported by MongoDB driver.`,
×
1042
        )
×
1043
    }
×
1044

26✔
1045
    /**
26✔
1046
     * Drops check constraints.
26✔
1047
     */
26✔
1048
    async dropCheckConstraints(
26✔
1049
        tableOrName: Table | string,
×
1050
        checkConstraints: TableCheck[],
×
1051
    ): Promise<void> {
×
1052
        throw new TypeORMError(
×
1053
            `Schema update queries are not supported by MongoDB driver.`,
×
1054
        )
×
1055
    }
×
1056

26✔
1057
    /**
26✔
1058
     * Creates a new exclusion constraint.
26✔
1059
     */
26✔
1060
    async createExclusionConstraint(
26✔
1061
        tableOrName: Table | string,
×
1062
        exclusionConstraint: TableExclusion,
×
1063
    ): Promise<void> {
×
1064
        throw new TypeORMError(
×
1065
            `Schema update queries are not supported by MongoDB driver.`,
×
1066
        )
×
1067
    }
×
1068

26✔
1069
    /**
26✔
1070
     * Creates a new exclusion constraints.
26✔
1071
     */
26✔
1072
    async createExclusionConstraints(
26✔
1073
        tableOrName: Table | string,
×
1074
        exclusionConstraints: TableExclusion[],
×
1075
    ): Promise<void> {
×
1076
        throw new TypeORMError(
×
1077
            `Schema update queries are not supported by MongoDB driver.`,
×
1078
        )
×
1079
    }
×
1080

26✔
1081
    /**
26✔
1082
     * Drops exclusion constraint.
26✔
1083
     */
26✔
1084
    async dropExclusionConstraint(
26✔
1085
        tableOrName: Table | string,
×
1086
        exclusionOrName: TableExclusion | string,
×
1087
    ): Promise<void> {
×
1088
        throw new TypeORMError(
×
1089
            `Schema update queries are not supported by MongoDB driver.`,
×
1090
        )
×
1091
    }
×
1092

26✔
1093
    /**
26✔
1094
     * Drops exclusion constraints.
26✔
1095
     */
26✔
1096
    async dropExclusionConstraints(
26✔
1097
        tableOrName: Table | string,
×
1098
        exclusionConstraints: TableExclusion[],
×
1099
    ): Promise<void> {
×
1100
        throw new TypeORMError(
×
1101
            `Schema update queries are not supported by MongoDB driver.`,
×
1102
        )
×
1103
    }
×
1104

26✔
1105
    /**
26✔
1106
     * Creates a new foreign key.
26✔
1107
     */
26✔
1108
    async createForeignKey(
26✔
1109
        tableOrName: Table | string,
×
1110
        foreignKey: TableForeignKey,
×
1111
    ): Promise<void> {
×
1112
        throw new TypeORMError(
×
1113
            `Schema update queries are not supported by MongoDB driver.`,
×
1114
        )
×
1115
    }
×
1116

26✔
1117
    /**
26✔
1118
     * Creates a new foreign keys.
26✔
1119
     */
26✔
1120
    async createForeignKeys(
26✔
1121
        tableOrName: Table | string,
×
1122
        foreignKeys: TableForeignKey[],
×
1123
    ): Promise<void> {
×
1124
        throw new TypeORMError(
×
1125
            `Schema update queries are not supported by MongoDB driver.`,
×
1126
        )
×
1127
    }
×
1128

26✔
1129
    /**
26✔
1130
     * Drops a foreign key from the table.
26✔
1131
     */
26✔
1132
    async dropForeignKey(
26✔
1133
        tableOrName: Table | string,
×
1134
        foreignKey: TableForeignKey,
×
1135
    ): Promise<void> {
×
1136
        throw new TypeORMError(
×
1137
            `Schema update queries are not supported by MongoDB driver.`,
×
1138
        )
×
1139
    }
×
1140

26✔
1141
    /**
26✔
1142
     * Drops a foreign keys from the table.
26✔
1143
     */
26✔
1144
    async dropForeignKeys(
26✔
1145
        tableOrName: Table | string,
×
1146
        foreignKeys: TableForeignKey[],
×
1147
    ): Promise<void> {
×
1148
        throw new TypeORMError(
×
1149
            `Schema update queries are not supported by MongoDB driver.`,
×
1150
        )
×
1151
    }
×
1152

26✔
1153
    /**
26✔
1154
     * Creates a new index.
26✔
1155
     */
26✔
1156
    async createIndex(
26✔
1157
        tableOrName: Table | string,
×
1158
        index: TableIndex,
×
1159
    ): Promise<void> {
×
1160
        throw new TypeORMError(
×
1161
            `Schema update queries are not supported by MongoDB driver.`,
×
1162
        )
×
1163
    }
×
1164

26✔
1165
    /**
26✔
1166
     * Creates a new indices
26✔
1167
     */
26✔
1168
    async createIndices(
26✔
1169
        tableOrName: Table | string,
×
1170
        indices: TableIndex[],
×
1171
    ): Promise<void> {
×
1172
        throw new TypeORMError(
×
1173
            `Schema update queries are not supported by MongoDB driver.`,
×
1174
        )
×
1175
    }
×
1176

26✔
1177
    /**
26✔
1178
     * Drops an index from the table.
26✔
1179
     */
26✔
1180
    async dropIndex(collectionName: string, indexName: string): Promise<void> {
26✔
1181
        throw new TypeORMError(
×
1182
            `Schema update queries are not supported by MongoDB driver.`,
×
1183
        )
×
1184
    }
×
1185

26✔
1186
    /**
26✔
1187
     * Drops an indices from the table.
26✔
1188
     */
26✔
1189
    async dropIndices(
26✔
1190
        tableOrName: Table | string,
×
1191
        indices: TableIndex[],
×
1192
    ): Promise<void> {
×
1193
        throw new TypeORMError(
×
1194
            `Schema update queries are not supported by MongoDB driver.`,
×
1195
        )
×
1196
    }
×
1197

26✔
1198
    /**
26✔
1199
     * Drops collection.
26✔
1200
     */
26✔
1201
    async clearTable(collectionName: string): Promise<void> {
26✔
1202
        await this.databaseConnection
4✔
1203
            .db(this.connection.driver.database!)
4✔
1204
            .dropCollection(collectionName)
4✔
1205
    }
4✔
1206

26✔
1207
    /**
26✔
1208
     * Enables special query runner mode in which sql queries won't be executed,
26✔
1209
     * instead they will be memorized into a special variable inside query runner.
26✔
1210
     * You can get memorized sql using getMemorySql() method.
26✔
1211
     */
26✔
1212
    enableSqlMemory(): void {
26✔
1213
        throw new TypeORMError(
×
1214
            `This operation is not supported by MongoDB driver.`,
×
1215
        )
×
1216
    }
×
1217

26✔
1218
    /**
26✔
1219
     * Disables special query runner mode in which sql queries won't be executed
26✔
1220
     * started by calling enableSqlMemory() method.
26✔
1221
     *
26✔
1222
     * Previously memorized sql will be flushed.
26✔
1223
     */
26✔
1224
    disableSqlMemory(): void {
26✔
1225
        throw new TypeORMError(
×
1226
            `This operation is not supported by MongoDB driver.`,
×
1227
        )
×
1228
    }
×
1229

26✔
1230
    /**
26✔
1231
     * Flushes all memorized sqls.
26✔
1232
     */
26✔
1233
    clearSqlMemory(): void {
26✔
1234
        throw new TypeORMError(
×
1235
            `This operation is not supported by MongoDB driver.`,
×
1236
        )
×
1237
    }
×
1238

26✔
1239
    /**
26✔
1240
     * Gets sql stored in the memory. Parameters in the sql are already replaced.
26✔
1241
     */
26✔
1242
    getMemorySql(): SqlInMemory {
26✔
1243
        throw new TypeORMError(
×
1244
            `This operation is not supported by MongoDB driver.`,
×
1245
        )
×
1246
    }
×
1247

26✔
1248
    /**
26✔
1249
     * Executes up sql queries.
26✔
1250
     */
26✔
1251
    async executeMemoryUpSql(): Promise<void> {
26✔
1252
        throw new TypeORMError(
×
1253
            `This operation is not supported by MongoDB driver.`,
×
1254
        )
×
1255
    }
×
1256

26✔
1257
    /**
26✔
1258
     * Executes down sql queries.
26✔
1259
     */
26✔
1260
    async executeMemoryDownSql(): Promise<void> {
26✔
1261
        throw new TypeORMError(
×
1262
            `This operation is not supported by MongoDB driver.`,
×
1263
        )
×
1264
    }
×
1265

26✔
1266
    // -------------------------------------------------------------------------
26✔
1267
    // Protected Methods
26✔
1268
    // -------------------------------------------------------------------------
26✔
1269

26✔
1270
    /**
26✔
1271
     * Gets collection from the database with a given name.
26✔
1272
     */
26✔
1273
    protected getCollection(collectionName: string): Collection<any> {
26✔
1274
        return this.databaseConnection
510✔
1275
            .db(this.connection.driver.database!)
510✔
1276
            .collection(collectionName)
510✔
1277
    }
510✔
1278

26✔
1279
    /**
26✔
1280
     * Change table comment.
26✔
1281
     */
26✔
1282
    changeTableComment(
26✔
1283
        tableOrName: Table | string,
×
1284
        comment?: string,
×
1285
    ): Promise<void> {
×
1286
        throw new TypeORMError(
×
1287
            `mongodb driver does not support change table comment.`,
×
1288
        )
×
1289
    }
×
1290
}
26✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc