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

typeorm / typeorm / 15089093306

17 May 2025 09:03PM UTC coverage: 50.109% (-26.2%) from 76.346%
15089093306

Pull #11437

github

naorpeled
add comment about vector <#>
Pull Request #11437: feat(postgres): support vector data type

5836 of 12767 branches covered (45.71%)

Branch coverage included in aggregate %.

16 of 17 new or added lines in 4 files covered. (94.12%)

6283 existing lines in 64 files now uncovered.

12600 of 24025 relevant lines covered (52.45%)

28708.0 hits per line

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

6.0
/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"
6✔
13
import { TableCheck } from "../../schema-builder/table/TableCheck"
14
import { TableExclusion } from "../../schema-builder/table/TableExclusion"
15
import { TypeORMError } from "../../error"
6✔
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 {
6✔
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
12✔
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
12✔
96

97
    /**
98
     * Stores temporarily user data.
99
     * Useful for sharing data with subscribers.
100
     */
101
    data = {}
12✔
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
12✔
124
        this.databaseConnection = databaseConnection
12✔
125
        this.broadcaster = new Broadcaster(this)
12✔
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> {
UNCOV
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> {
UNCOV
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> {
UNCOV
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> {
UNCOV
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> {
UNCOV
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> {
UNCOV
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> {
UNCOV
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> {
UNCOV
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> {
UNCOV
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
     * Unsupported - Executing SQL query is not supported by MongoDB driver.
579
     */
580
    async sql(
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

589
    /**
590
     * Returns raw data stream.
591
     */
592
    stream(
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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

743
    /**
744
     * Checks if column with the given name exist in the given table.
745
     */
746
    async hasColumn(
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

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

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

773
    /**
774
     * Creates a new table schema.
775
     */
776
    async createSchema(
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

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

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

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

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

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

830
    /**
831
     * Renames the given table.
832
     */
833
    async renameTable(
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

842
    /**
843
     * Creates a new column from the column in the table.
844
     */
845
    async addColumn(
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

854
    /**
855
     * Creates a new columns from the column in the table.
856
     */
857
    async addColumns(
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

866
    /**
867
     * Renames column in the given table.
868
     */
869
    async renameColumn(
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

879
    /**
880
     * Changes a column in the table.
881
     */
882
    async changeColumn(
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

892
    /**
893
     * Changes a column in the table.
894
     */
895
    async changeColumns(
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

904
    /**
905
     * Drops column in the table.
906
     */
907
    async dropColumn(
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

916
    /**
917
     * Drops the columns in the table.
918
     */
919
    async dropColumns(
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

928
    /**
929
     * Creates a new primary key.
930
     */
931
    async createPrimaryKey(
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

940
    /**
941
     * Updates composite primary keys.
942
     */
943
    async updatePrimaryKeys(
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

952
    /**
953
     * Drops a primary key.
954
     */
955
    async dropPrimaryKey(tableOrName: Table | string): 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 constraint.
963
     */
964
    async createUniqueConstraint(
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

973
    /**
974
     * Creates a new unique constraints.
975
     */
976
    async createUniqueConstraints(
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

985
    /**
986
     * Drops an unique constraint.
987
     */
988
    async dropUniqueConstraint(
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

997
    /**
998
     * Drops an unique constraints.
999
     */
1000
    async dropUniqueConstraints(
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

1009
    /**
1010
     * Creates a new check constraint.
1011
     */
1012
    async createCheckConstraint(
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

1021
    /**
1022
     * Creates a new check constraints.
1023
     */
1024
    async createCheckConstraints(
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

1033
    /**
1034
     * Drops check constraint.
1035
     */
1036
    async dropCheckConstraint(
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

1045
    /**
1046
     * Drops check constraints.
1047
     */
1048
    async dropCheckConstraints(
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

1057
    /**
1058
     * Creates a new exclusion constraint.
1059
     */
1060
    async createExclusionConstraint(
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

1069
    /**
1070
     * Creates a new exclusion constraints.
1071
     */
1072
    async createExclusionConstraints(
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

1081
    /**
1082
     * Drops exclusion constraint.
1083
     */
1084
    async dropExclusionConstraint(
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

1093
    /**
1094
     * Drops exclusion constraints.
1095
     */
1096
    async dropExclusionConstraints(
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

1105
    /**
1106
     * Creates a new foreign key.
1107
     */
1108
    async createForeignKey(
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

1117
    /**
1118
     * Creates a new foreign keys.
1119
     */
1120
    async createForeignKeys(
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

1129
    /**
1130
     * Drops a foreign key from the table.
1131
     */
1132
    async dropForeignKey(
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

1141
    /**
1142
     * Drops a foreign keys from the table.
1143
     */
1144
    async dropForeignKeys(
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

1153
    /**
1154
     * Creates a new index.
1155
     */
1156
    async createIndex(
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

1165
    /**
1166
     * Creates a new indices
1167
     */
1168
    async createIndices(
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

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

1186
    /**
1187
     * Drops an indices from the table.
1188
     */
1189
    async dropIndices(
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

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

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

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

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

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

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

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

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

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

1279
    /**
1280
     * Change table comment.
1281
     */
1282
    changeTableComment(
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
}
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