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

typeorm / typeorm / 14796576772

02 May 2025 01:52PM UTC coverage: 45.367% (-30.9%) from 76.309%
14796576772

Pull #11434

github

web-flow
Merge ec4ce2d00 into fadad1a74
Pull Request #11434: feat: release PR releases using pkg.pr.new

5216 of 12761 branches covered (40.87%)

Branch coverage included in aggregate %.

11439 of 23951 relevant lines covered (47.76%)

15712.55 hits per line

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

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

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

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

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

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

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

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

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

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

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

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

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

118
    // -------------------------------------------------------------------------
119
    // Constructor
120
    // -------------------------------------------------------------------------
121

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

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

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

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

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

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

167
    /**
168
     * Perform a bulkWrite operation without a fluent API.
169
     */
170
    async bulkWrite(
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

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

195
    /**
196
     * Count number of matching documents in the db to a query.
197
     */
198
    async countDocuments(
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

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

223
    /**
224
     * Creates multiple indexes in the collection, this method is only supported for MongoDB 2.6 or higher.
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/.
226
     */
227
    async createCollectionIndexes(
228
        collectionName: string,
229
        indexSpecs: IndexDescription[],
230
    ): Promise<string[]> {
231
        return this.getCollection(collectionName).createIndexes(indexSpecs)
×
232
    }
233

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

248
    /**
249
     * Delete a document on MongoDB.
250
     */
251
    async deleteOne(
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

262
    /**
263
     * The distinct command returns returns a list of distinct values for the given key across a collection.
264
     */
265
    async distinct(
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

278
    /**
279
     * Drops an index from this collection.
280
     */
281
    async dropCollectionIndex(
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

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

299
    /**
300
     * Find a document and delete it in one atomic operation, requires a write lock for the duration of the operation.
301
     */
302
    async findOneAndDelete(
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

313
    /**
314
     * Find a document and replace it in one atomic operation, requires a write lock for the duration of the operation.
315
     */
316
    async findOneAndReplace(
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

329
    /**
330
     * Find a document and update it in one atomic operation, requires a write lock for the duration of the operation.
331
     */
332
    async findOneAndUpdate(
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

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

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

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

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

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

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

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

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

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

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

451
    /**
452
     * Replace a document on MongoDB.
453
     */
454
    async replaceOne(
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

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

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

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

504
    /**
505
     * Update a single document on MongoDB.
506
     */
507
    async updateOne(
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

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

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

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

540
    /**
541
     * For MongoDB database we don't release connection, because its single connection.
542
     */
543
    async release(): Promise<void> {
544
        // releasing connection are not supported by mongodb driver, so simply don't do anything here
545
    }
546

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

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

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

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

577
    /**
578
     * Returns raw data stream.
579
     */
580
    stream(
581
        query: string,
582
        parameters?: any[],
583
        onEnd?: Function,
584
        onError?: Function,
585
    ): Promise<ReadStream> {
586
        throw new TypeORMError(
×
587
            `Stream is not supported by MongoDB driver. Use watch instead.`,
588
        )
589
    }
590

591
    /**
592
     * Insert a new row with given values into the given table.
593
     * Returns value of inserted object id.
594

595
    async insert(collectionName: string, keyValues: ObjectLiteral): Promise<any> { // todo: fix any
596
        const results = await this.databaseConnection
597
            .collection(collectionName)
598
            .insertOne(keyValues);
599
        const generatedMap = this.connection.getMetadata(collectionName).objectIdColumn!.createValueMap(results.insertedId);
600
        return {
601
            result: results,
602
            generatedMap: generatedMap
603
        };
604
    }*/
605

606
    /**
607
     * Updates rows that match given conditions in the given table.
608

609
    async update(collectionName: string, valuesMap: ObjectLiteral, conditions: ObjectLiteral): Promise<any> { // todo: fix any
610
        await this.databaseConnection
611
            .collection(collectionName)
612
            .updateOne(conditions, valuesMap);
613
    }*/
614

615
    /**
616
     * Deletes from the given table by a given conditions.
617

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

622
        await this.databaseConnection
623
            .collection(collectionName)
624
            .deleteOne(conditions);
625
    }*/
626

627
    /**
628
     * Returns all available database names including system databases.
629
     */
630
    async getDatabases(): Promise<string[]> {
631
        throw new TypeORMError(
×
632
            `Schema update queries are not supported by MongoDB driver.`,
633
        )
634
    }
635

636
    /**
637
     * Returns all available schema names including system schemas.
638
     * If database parameter specified, returns schemas of that database.
639
     */
640
    async getSchemas(database?: string): Promise<string[]> {
641
        throw new TypeORMError(
×
642
            `Schema update queries are not supported by MongoDB driver.`,
643
        )
644
    }
645

646
    /**
647
     * Loads given table's data from the database.
648
     */
649
    async getTable(collectionName: string): Promise<Table | undefined> {
650
        throw new TypeORMError(
×
651
            `Schema update queries are not supported by MongoDB driver.`,
652
        )
653
    }
654

655
    /**
656
     * Loads all tables (with given names) from the database and creates a Table from them.
657
     */
658
    async getTables(collectionNames: string[]): Promise<Table[]> {
659
        throw new TypeORMError(
×
660
            `Schema update queries are not supported by MongoDB driver.`,
661
        )
662
    }
663

664
    /**
665
     * Loads given views's data from the database.
666
     */
667
    async getView(collectionName: string): Promise<View | undefined> {
668
        throw new TypeORMError(
×
669
            `Schema update queries are not supported by MongoDB driver.`,
670
        )
671
    }
672

673
    /**
674
     * Loads all views (with given names) from the database and creates a Table from them.
675
     */
676
    async getViews(collectionNames: string[]): Promise<View[]> {
677
        throw new TypeORMError(
×
678
            `Schema update queries are not supported by MongoDB driver.`,
679
        )
680
    }
681

682
    getReplicationMode(): ReplicationMode {
683
        return "master"
×
684
    }
685

686
    /**
687
     * Checks if database with the given name exist.
688
     */
689
    async hasDatabase(database: string): Promise<boolean> {
690
        throw new TypeORMError(
×
691
            `Check database queries are not supported by MongoDB driver.`,
692
        )
693
    }
694

695
    /**
696
     * Loads currently using database
697
     */
698
    async getCurrentDatabase(): Promise<undefined> {
699
        throw new TypeORMError(
×
700
            `Check database queries are not supported by MongoDB driver.`,
701
        )
702
    }
703

704
    /**
705
     * Checks if schema with the given name exist.
706
     */
707
    async hasSchema(schema: string): Promise<boolean> {
708
        throw new TypeORMError(
×
709
            `Check schema queries are not supported by MongoDB driver.`,
710
        )
711
    }
712

713
    /**
714
     * Loads currently using database schema
715
     */
716
    async getCurrentSchema(): Promise<undefined> {
717
        throw new TypeORMError(
×
718
            `Check schema queries are not supported by MongoDB driver.`,
719
        )
720
    }
721

722
    /**
723
     * Checks if table with the given name exist in the database.
724
     */
725
    async hasTable(collectionName: string): Promise<boolean> {
726
        throw new TypeORMError(
×
727
            `Check schema queries are not supported by MongoDB driver.`,
728
        )
729
    }
730

731
    /**
732
     * Checks if column with the given name exist in the given table.
733
     */
734
    async hasColumn(
735
        tableOrName: Table | string,
736
        columnName: string,
737
    ): Promise<boolean> {
738
        throw new TypeORMError(
×
739
            `Schema update queries are not supported by MongoDB driver.`,
740
        )
741
    }
742

743
    /**
744
     * Creates a database if it's not created.
745
     */
746
    async createDatabase(database: string): Promise<void> {
747
        throw new TypeORMError(
×
748
            `Database create queries are not supported by MongoDB driver.`,
749
        )
750
    }
751

752
    /**
753
     * Drops database.
754
     */
755
    async dropDatabase(database: string, ifExist?: boolean): Promise<void> {
756
        throw new TypeORMError(
×
757
            `Database drop queries are not supported by MongoDB driver.`,
758
        )
759
    }
760

761
    /**
762
     * Creates a new table schema.
763
     */
764
    async createSchema(
765
        schemaPath: string,
766
        ifNotExist?: boolean,
767
    ): Promise<void> {
768
        throw new TypeORMError(
×
769
            `Schema create queries are not supported by MongoDB driver.`,
770
        )
771
    }
772

773
    /**
774
     * Drops table schema.
775
     */
776
    async dropSchema(schemaPath: string, ifExist?: boolean): Promise<void> {
777
        throw new TypeORMError(
×
778
            `Schema drop queries are not supported by MongoDB driver.`,
779
        )
780
    }
781

782
    /**
783
     * Creates a new table from the given table and columns inside it.
784
     */
785
    async createTable(table: Table): Promise<void> {
786
        throw new TypeORMError(
×
787
            `Schema update queries are not supported by MongoDB driver.`,
788
        )
789
    }
790

791
    /**
792
     * Drops the table.
793
     */
794
    async dropTable(tableName: Table | string): Promise<void> {
795
        throw new TypeORMError(
×
796
            `Schema update queries are not supported by MongoDB driver.`,
797
        )
798
    }
799

800
    /**
801
     * Creates a new view.
802
     */
803
    async createView(view: View): Promise<void> {
804
        throw new TypeORMError(
×
805
            `Schema update queries are not supported by MongoDB driver.`,
806
        )
807
    }
808

809
    /**
810
     * Drops the view.
811
     */
812
    async dropView(target: View | string): Promise<void> {
813
        throw new TypeORMError(
×
814
            `Schema update queries are not supported by MongoDB driver.`,
815
        )
816
    }
817

818
    /**
819
     * Renames the given table.
820
     */
821
    async renameTable(
822
        oldTableOrName: Table | string,
823
        newTableOrName: Table | string,
824
    ): Promise<void> {
825
        throw new TypeORMError(
×
826
            `Schema update queries are not supported by MongoDB driver.`,
827
        )
828
    }
829

830
    /**
831
     * Creates a new column from the column in the table.
832
     */
833
    async addColumn(
834
        tableOrName: Table | string,
835
        column: TableColumn,
836
    ): Promise<void> {
837
        throw new TypeORMError(
×
838
            `Schema update queries are not supported by MongoDB driver.`,
839
        )
840
    }
841

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

854
    /**
855
     * Renames column in the given table.
856
     */
857
    async renameColumn(
858
        tableOrName: Table | string,
859
        oldTableColumnOrName: TableColumn | string,
860
        newTableColumnOrName: TableColumn | string,
861
    ): Promise<void> {
862
        throw new TypeORMError(
×
863
            `Schema update queries are not supported by MongoDB driver.`,
864
        )
865
    }
866

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

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

892
    /**
893
     * Drops column in the table.
894
     */
895
    async dropColumn(
896
        tableOrName: Table | string,
897
        columnOrName: TableColumn | string,
898
    ): Promise<void> {
899
        throw new TypeORMError(
×
900
            `Schema update queries are not supported by MongoDB driver.`,
901
        )
902
    }
903

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

916
    /**
917
     * Creates a new primary key.
918
     */
919
    async createPrimaryKey(
920
        tableOrName: Table | string,
921
        columnNames: string[],
922
    ): Promise<void> {
923
        throw new TypeORMError(
×
924
            `Schema update queries are not supported by MongoDB driver.`,
925
        )
926
    }
927

928
    /**
929
     * Updates composite primary keys.
930
     */
931
    async updatePrimaryKeys(
932
        tableOrName: Table | string,
933
        columns: TableColumn[],
934
    ): Promise<void> {
935
        throw new TypeORMError(
×
936
            `Schema update queries are not supported by MongoDB driver.`,
937
        )
938
    }
939

940
    /**
941
     * Drops a primary key.
942
     */
943
    async dropPrimaryKey(tableOrName: Table | string): Promise<void> {
944
        throw new TypeORMError(
×
945
            `Schema update queries are not supported by MongoDB driver.`,
946
        )
947
    }
948

949
    /**
950
     * Creates a new unique constraint.
951
     */
952
    async createUniqueConstraint(
953
        tableOrName: Table | string,
954
        uniqueConstraint: TableUnique,
955
    ): Promise<void> {
956
        throw new TypeORMError(
×
957
            `Schema update queries are not supported by MongoDB driver.`,
958
        )
959
    }
960

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

973
    /**
974
     * Drops an unique constraint.
975
     */
976
    async dropUniqueConstraint(
977
        tableOrName: Table | string,
978
        uniqueOrName: TableUnique | string,
979
    ): Promise<void> {
980
        throw new TypeORMError(
×
981
            `Schema update queries are not supported by MongoDB driver.`,
982
        )
983
    }
984

985
    /**
986
     * Drops an unique constraints.
987
     */
988
    async dropUniqueConstraints(
989
        tableOrName: Table | string,
990
        uniqueConstraints: TableUnique[],
991
    ): Promise<void> {
992
        throw new TypeORMError(
×
993
            `Schema update queries are not supported by MongoDB driver.`,
994
        )
995
    }
996

997
    /**
998
     * Creates a new check constraint.
999
     */
1000
    async createCheckConstraint(
1001
        tableOrName: Table | string,
1002
        checkConstraint: TableCheck,
1003
    ): Promise<void> {
1004
        throw new TypeORMError(
×
1005
            `Schema update queries are not supported by MongoDB driver.`,
1006
        )
1007
    }
1008

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

1021
    /**
1022
     * Drops check constraint.
1023
     */
1024
    async dropCheckConstraint(
1025
        tableOrName: Table | string,
1026
        checkOrName: TableCheck | string,
1027
    ): Promise<void> {
1028
        throw new TypeORMError(
×
1029
            `Schema update queries are not supported by MongoDB driver.`,
1030
        )
1031
    }
1032

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

1045
    /**
1046
     * Creates a new exclusion constraint.
1047
     */
1048
    async createExclusionConstraint(
1049
        tableOrName: Table | string,
1050
        exclusionConstraint: TableExclusion,
1051
    ): Promise<void> {
1052
        throw new TypeORMError(
×
1053
            `Schema update queries are not supported by MongoDB driver.`,
1054
        )
1055
    }
1056

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

1069
    /**
1070
     * Drops exclusion constraint.
1071
     */
1072
    async dropExclusionConstraint(
1073
        tableOrName: Table | string,
1074
        exclusionOrName: TableExclusion | string,
1075
    ): Promise<void> {
1076
        throw new TypeORMError(
×
1077
            `Schema update queries are not supported by MongoDB driver.`,
1078
        )
1079
    }
1080

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

1093
    /**
1094
     * Creates a new foreign key.
1095
     */
1096
    async createForeignKey(
1097
        tableOrName: Table | string,
1098
        foreignKey: TableForeignKey,
1099
    ): Promise<void> {
1100
        throw new TypeORMError(
×
1101
            `Schema update queries are not supported by MongoDB driver.`,
1102
        )
1103
    }
1104

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

1117
    /**
1118
     * Drops a foreign key from the table.
1119
     */
1120
    async dropForeignKey(
1121
        tableOrName: Table | string,
1122
        foreignKey: TableForeignKey,
1123
    ): Promise<void> {
1124
        throw new TypeORMError(
×
1125
            `Schema update queries are not supported by MongoDB driver.`,
1126
        )
1127
    }
1128

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

1141
    /**
1142
     * Creates a new index.
1143
     */
1144
    async createIndex(
1145
        tableOrName: Table | string,
1146
        index: TableIndex,
1147
    ): Promise<void> {
1148
        throw new TypeORMError(
×
1149
            `Schema update queries are not supported by MongoDB driver.`,
1150
        )
1151
    }
1152

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

1165
    /**
1166
     * Drops an index from the table.
1167
     */
1168
    async dropIndex(collectionName: string, indexName: string): Promise<void> {
1169
        throw new TypeORMError(
×
1170
            `Schema update queries are not supported by MongoDB driver.`,
1171
        )
1172
    }
1173

1174
    /**
1175
     * Drops an indices from the table.
1176
     */
1177
    async dropIndices(
1178
        tableOrName: Table | string,
1179
        indices: TableIndex[],
1180
    ): Promise<void> {
1181
        throw new TypeORMError(
×
1182
            `Schema update queries are not supported by MongoDB driver.`,
1183
        )
1184
    }
1185

1186
    /**
1187
     * Drops collection.
1188
     */
1189
    async clearTable(collectionName: string): Promise<void> {
1190
        await this.databaseConnection
×
1191
            .db(this.connection.driver.database!)
1192
            .dropCollection(collectionName)
1193
    }
1194

1195
    /**
1196
     * Enables special query runner mode in which sql queries won't be executed,
1197
     * instead they will be memorized into a special variable inside query runner.
1198
     * You can get memorized sql using getMemorySql() method.
1199
     */
1200
    enableSqlMemory(): void {
1201
        throw new TypeORMError(
×
1202
            `This operation is not supported by MongoDB driver.`,
1203
        )
1204
    }
1205

1206
    /**
1207
     * Disables special query runner mode in which sql queries won't be executed
1208
     * started by calling enableSqlMemory() method.
1209
     *
1210
     * Previously memorized sql will be flushed.
1211
     */
1212
    disableSqlMemory(): void {
1213
        throw new TypeORMError(
×
1214
            `This operation is not supported by MongoDB driver.`,
1215
        )
1216
    }
1217

1218
    /**
1219
     * Flushes all memorized sqls.
1220
     */
1221
    clearSqlMemory(): void {
1222
        throw new TypeORMError(
×
1223
            `This operation is not supported by MongoDB driver.`,
1224
        )
1225
    }
1226

1227
    /**
1228
     * Gets sql stored in the memory. Parameters in the sql are already replaced.
1229
     */
1230
    getMemorySql(): SqlInMemory {
1231
        throw new TypeORMError(
×
1232
            `This operation is not supported by MongoDB driver.`,
1233
        )
1234
    }
1235

1236
    /**
1237
     * Executes up sql queries.
1238
     */
1239
    async executeMemoryUpSql(): Promise<void> {
1240
        throw new TypeORMError(
×
1241
            `This operation is not supported by MongoDB driver.`,
1242
        )
1243
    }
1244

1245
    /**
1246
     * Executes down sql queries.
1247
     */
1248
    async executeMemoryDownSql(): Promise<void> {
1249
        throw new TypeORMError(
×
1250
            `This operation is not supported by MongoDB driver.`,
1251
        )
1252
    }
1253

1254
    // -------------------------------------------------------------------------
1255
    // Protected Methods
1256
    // -------------------------------------------------------------------------
1257

1258
    /**
1259
     * Gets collection from the database with a given name.
1260
     */
1261
    protected getCollection(collectionName: string): Collection<any> {
1262
        return this.databaseConnection
×
1263
            .db(this.connection.driver.database!)
1264
            .collection(collectionName)
1265
    }
1266

1267
    /**
1268
     * Change table comment.
1269
     */
1270
    changeTableComment(
1271
        tableOrName: Table | string,
1272
        comment?: string,
1273
    ): Promise<void> {
1274
        throw new TypeORMError(
×
1275
            `mongodb driver does not support change table comment.`,
1276
        )
1277
    }
1278
}
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

© 2025 Coveralls, Inc