Skip to main content
Module

x/typeorm/src/index.ts>MongoRepository

Forked from https://github.com/typeorm/typeorm
Latest
class MongoRepository
extends Repository<Entity>
Re-export
import { MongoRepository } from "https://deno.land/x/typeorm@v0.2.23-rc10/src/index.ts";

Repository used to manage mongodb documents of a single entity type.

Type Parameters

Entity extends ObjectLiteral

Properties

readonly
manager: MongoEntityManager

Entity Manager used by this repository.

Methods

aggregate<R = any>(pipeline: ObjectLiteral[], options?: CollectionAggregationOptions): AggregationCursor<R>

Execute an aggregation framework pipeline against the collection.

aggregateEntity(pipeline: ObjectLiteral[], options?: CollectionAggregationOptions): AggregationCursor<Entity>

Execute an aggregation framework pipeline against the collection. This returns modified version of cursor that transforms each result into Entity model.

bulkWrite(operations: ObjectLiteral[], options?: CollectionBulkWriteOptions): Promise<BulkWriteOpResultObject>

Perform a bulkWrite operation without a fluent API.

collectionIndexes(): Promise<any>

Retrieve all the indexes on the collection.

collectionIndexExists(indexes: string | string[]): Promise<boolean>

Retrieve all the indexes on the collection.

collectionIndexInformation(options?: { full: boolean; }): Promise<any>

Retrieves this collections index info.

count(query?: ObjectLiteral, options?: MongoCountPreferences): Promise<number>

Count number of matching documents in the db to a query.

createCollectionIndex(fieldOrSpec: string | any, options?: MongodbIndexOptions): Promise<string>

Creates an index on the db and collection.

createCollectionIndexes(indexSpecs: ObjectLiteral[]): Promise<void>

Creates multiple indexes in the collection, this method is only supported for MongoDB 2.6 or higher. Earlier version of MongoDB will throw a command not supported error. Index specifications are defined at http://docs.mongodb.org/manual/reference/command/createIndexes/.

createCursor<T = any>(query?: ObjectLiteral): Cursor<T>

Creates a cursor for a query that can be used to iterate over results from MongoDB.

createEntityCursor(query?: ObjectLiteral): Cursor<Entity>

Creates a cursor for a query that can be used to iterate over results from MongoDB. This returns modified version of cursor that transforms each result into Entity model.

createQueryBuilder(alias: string, queryRunner?: QueryRunner): SelectQueryBuilder<Entity>

Using Query Builder with MongoDB is not supported yet. Calling this method will return an error.

deleteMany(query: ObjectLiteral, options?: CollectionOptions): Promise<DeleteWriteOpResultObject>

Delete multiple documents on MongoDB.

deleteOne(query: ObjectLiteral, options?: CollectionOptions): Promise<DeleteWriteOpResultObject>

Delete a document on MongoDB.

distinct(
key: string,
query: ObjectLiteral,
options?: { readPreference?: ReadPreference | string; },
): Promise<any>

The distinct command returns returns a list of distinct values for the given key across a collection.

dropCollectionIndex(indexName: string, options?: CollectionOptions): Promise<any>

Drops an index from this collection.

dropCollectionIndexes(): Promise<any>

Drops all indexes from the collection.

find(optionsOrConditions?: FindManyOptions<Entity> | Partial<Entity>): Promise<Entity[]>

Finds entities that match given find options or conditions.

findAndCount(optionsOrConditions?: FindManyOptions<Entity> | Partial<Entity>): Promise<[Entity[], number]>

Finds entities that match given find options or conditions. Also counts all entities that match given conditions, but ignores pagination settings (from and take options).

findByIds(ids: any[], optionsOrConditions?: FindManyOptions<Entity> | Partial<Entity>): Promise<Entity[]>

Finds entities by ids. Optionally find options can be applied.

findOne(optionsOrConditions?:
| string
| number
| Date
| ObjectID
| FindOneOptions<Entity>
| Partial<Entity>
, maybeOptions?: FindOneOptions<Entity>
): Promise<Entity | undefined>

Finds first entity that matches given conditions and/or find options.

findOneAndDelete(query: ObjectLiteral, options?: { projection?: Object; sort?: Object; maxTimeMS?: number; }): Promise<FindAndModifyWriteOpResultObject>

Find a document and delete it in one atomic operation, requires a write lock for the duration of the operation.

findOneAndReplace(
query: ObjectLiteral,
replacement: Object,
options?: FindOneAndReplaceOption,
): Promise<FindAndModifyWriteOpResultObject>

Find a document and replace it in one atomic operation, requires a write lock for the duration of the operation.

findOneAndUpdate(
query: ObjectLiteral,
update: Object,
options?: FindOneAndReplaceOption,
): Promise<FindAndModifyWriteOpResultObject>

Find a document and update it in one atomic operation, requires a write lock for the duration of the operation.

geoHaystackSearch(
x: number,
y: number,
options?: GeoHaystackSearchOptions,
): Promise<any>

Execute a geo search using a geo haystack index on a collection.

geoNear(
x: number,
y: number,
options?: GeoNearOptions,
): Promise<any>

Execute the geoNear command to search for items in the collection.

group(
keys:
| Object
| Array<any>
| Function
| Code
,
condition: Object,
initial: Object,
reduce: Function | Code,
finalize: Function | Code,
command: boolean,
options?: { readPreference?: ReadPreference | string; },
): Promise<any>

Run a group command across a collection.

initializeOrderedBulkOp(options?: CollectionOptions): OrderedBulkOperation

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.

initializeUnorderedBulkOp(options?: CollectionOptions): UnorderedBulkOperation

Initiate a Out of order batch write operation. All operations will be buffered into insert/update/remove commands executed out of order.

insertMany(docs: ObjectLiteral[], options?: CollectionInsertManyOptions): Promise<InsertWriteOpResult>

Inserts an array of documents into MongoDB.

insertOne(doc: ObjectLiteral, options?: CollectionInsertOneOptions): Promise<InsertOneWriteOpResult>

Inserts a single document into MongoDB.

isCapped(): Promise<any>

Returns if the collection is a capped collection.

listCollectionIndexes(options?: { batchSize?: number; readPreference?: ReadPreference | string; }): CommandCursor

Get the list of all indexes information for the collection.

mapReduce(
map: Function | string,
reduce: Function | string,
options?: MapReduceOptions,
): Promise<any>

Run Map Reduce across a collection. Be aware that the inline option for out will return an array of results not a collection.

parallelCollectionScan(options?: ParallelCollectionScanOptions): Promise<Cursor<Entity>[]>

Return N number of parallel cursors for a collection allowing parallel reading of entire collection. There are no ordering guarantees for returned results.

query(query: string, parameters?: any[]): Promise<any>

Raw SQL query execution is not supported by MongoDB. Calling this method will return an error.

reIndex(): Promise<any>

Reindex all indexes on the collection Warning: reIndex is a blocking operation (indexes are rebuilt in the foreground) and will be slow for large collections.

rename(newName: string, options?: { dropTarget?: boolean; }): Promise<Collection<any>>

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.

replaceOne(
query: ObjectLiteral,
doc: ObjectLiteral,
options?: ReplaceOneOptions,
): Promise<UpdateWriteOpResult>

Replace a document on MongoDB.

stats(options?: { scale: number; }): Promise<CollStats>

Get all the collection statistics.

updateMany(
query: ObjectLiteral,
update: ObjectLiteral,
options?: { upsert?: boolean; w?: any; wtimeout?: number; j?: boolean; },
): Promise<UpdateWriteOpResult>

Update multiple documents on MongoDB.

updateOne(
query: ObjectLiteral,
update: ObjectLiteral,
options?: ReplaceOneOptions,
): Promise<UpdateWriteOpResult>

Update a single document on MongoDB.

Type Parameters

Entity extends ObjectLiteral

Properties

readonly
manager: MongoEntityManager

Entity Manager used by this repository.

Methods

aggregate<R = any>(pipeline: ObjectLiteral[], options?: CollectionAggregationOptions): AggregationCursor<R>

Execute an aggregation framework pipeline against the collection.

aggregateEntity(pipeline: ObjectLiteral[], options?: CollectionAggregationOptions): AggregationCursor<Entity>

Execute an aggregation framework pipeline against the collection. This returns modified version of cursor that transforms each result into Entity model.

bulkWrite(operations: ObjectLiteral[], options?: CollectionBulkWriteOptions): Promise<BulkWriteOpResultObject>

Perform a bulkWrite operation without a fluent API.

collectionIndexes(): Promise<any>

Retrieve all the indexes on the collection.

collectionIndexExists(indexes: string | string[]): Promise<boolean>

Retrieve all the indexes on the collection.

collectionIndexInformation(options?: { full: boolean; }): Promise<any>

Retrieves this collections index info.

count(query?: ObjectLiteral, options?: MongoCountPreferences): Promise<number>

Count number of matching documents in the db to a query.

createCollectionIndex(fieldOrSpec: string | any, options?: MongodbIndexOptions): Promise<string>

Creates an index on the db and collection.

createCollectionIndexes(indexSpecs: ObjectLiteral[]): Promise<void>

Creates multiple indexes in the collection, this method is only supported for MongoDB 2.6 or higher. Earlier version of MongoDB will throw a command not supported error. Index specifications are defined at http://docs.mongodb.org/manual/reference/command/createIndexes/.

createCursor<T = any>(query?: ObjectLiteral): Cursor<T>

Creates a cursor for a query that can be used to iterate over results from MongoDB.

createEntityCursor(query?: ObjectLiteral): Cursor<Entity>

Creates a cursor for a query that can be used to iterate over results from MongoDB. This returns modified version of cursor that transforms each result into Entity model.

createQueryBuilder(alias: string, queryRunner?: QueryRunner): SelectQueryBuilder<Entity>

Using Query Builder with MongoDB is not supported yet. Calling this method will return an error.

deleteMany(query: ObjectLiteral, options?: CollectionOptions): Promise<DeleteWriteOpResultObject>

Delete multiple documents on MongoDB.

deleteOne(query: ObjectLiteral, options?: CollectionOptions): Promise<DeleteWriteOpResultObject>

Delete a document on MongoDB.

distinct(
key: string,
query: ObjectLiteral,
options?: { readPreference?: ReadPreference | string; },
): Promise<any>

The distinct command returns returns a list of distinct values for the given key across a collection.

dropCollectionIndex(indexName: string, options?: CollectionOptions): Promise<any>

Drops an index from this collection.

dropCollectionIndexes(): Promise<any>

Drops all indexes from the collection.

find(optionsOrConditions?: FindManyOptions<Entity> | Partial<Entity>): Promise<Entity[]>

Finds entities that match given find options or conditions.

findAndCount(optionsOrConditions?: FindManyOptions<Entity> | Partial<Entity>): Promise<[Entity[], number]>

Finds entities that match given find options or conditions. Also counts all entities that match given conditions, but ignores pagination settings (from and take options).

findByIds(ids: any[], optionsOrConditions?: FindManyOptions<Entity> | Partial<Entity>): Promise<Entity[]>

Finds entities by ids. Optionally find options can be applied.

findOne(optionsOrConditions?:
| string
| number
| Date
| ObjectID
| FindOneOptions<Entity>
| Partial<Entity>
, maybeOptions?: FindOneOptions<Entity>
): Promise<Entity | undefined>

Finds first entity that matches given conditions and/or find options.

findOneAndDelete(query: ObjectLiteral, options?: { projection?: Object; sort?: Object; maxTimeMS?: number; }): Promise<FindAndModifyWriteOpResultObject>

Find a document and delete it in one atomic operation, requires a write lock for the duration of the operation.

findOneAndReplace(
query: ObjectLiteral,
replacement: Object,
options?: FindOneAndReplaceOption,
): Promise<FindAndModifyWriteOpResultObject>

Find a document and replace it in one atomic operation, requires a write lock for the duration of the operation.

findOneAndUpdate(
query: ObjectLiteral,
update: Object,
options?: FindOneAndReplaceOption,
): Promise<FindAndModifyWriteOpResultObject>

Find a document and update it in one atomic operation, requires a write lock for the duration of the operation.

geoHaystackSearch(
x: number,
y: number,
options?: GeoHaystackSearchOptions,
): Promise<any>

Execute a geo search using a geo haystack index on a collection.

geoNear(
x: number,
y: number,
options?: GeoNearOptions,
): Promise<any>

Execute the geoNear command to search for items in the collection.

group(
keys:
| Object
| Array<any>
| Function
| Code
,
condition: Object,
initial: Object,
reduce: Function | Code,
finalize: Function | Code,
command: boolean,
options?: { readPreference?: ReadPreference | string; },
): Promise<any>

Run a group command across a collection.

initializeOrderedBulkOp(options?: CollectionOptions): OrderedBulkOperation

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.

initializeUnorderedBulkOp(options?: CollectionOptions): UnorderedBulkOperation

Initiate a Out of order batch write operation. All operations will be buffered into insert/update/remove commands executed out of order.

insertMany(docs: ObjectLiteral[], options?: CollectionInsertManyOptions): Promise<InsertWriteOpResult>

Inserts an array of documents into MongoDB.

insertOne(doc: ObjectLiteral, options?: CollectionInsertOneOptions): Promise<InsertOneWriteOpResult>

Inserts a single document into MongoDB.

isCapped(): Promise<any>

Returns if the collection is a capped collection.

listCollectionIndexes(options?: { batchSize?: number; readPreference?: ReadPreference | string; }): CommandCursor

Get the list of all indexes information for the collection.

mapReduce(
map: Function | string,
reduce: Function | string,
options?: MapReduceOptions,
): Promise<any>

Run Map Reduce across a collection. Be aware that the inline option for out will return an array of results not a collection.

parallelCollectionScan(options?: ParallelCollectionScanOptions): Promise<Cursor<Entity>[]>

Return N number of parallel cursors for a collection allowing parallel reading of entire collection. There are no ordering guarantees for returned results.

query(query: string, parameters?: any[]): Promise<any>

Raw SQL query execution is not supported by MongoDB. Calling this method will return an error.

reIndex(): Promise<any>

Reindex all indexes on the collection Warning: reIndex is a blocking operation (indexes are rebuilt in the foreground) and will be slow for large collections.

rename(newName: string, options?: { dropTarget?: boolean; }): Promise<Collection<any>>

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.

replaceOne(
query: ObjectLiteral,
doc: ObjectLiteral,
options?: ReplaceOneOptions,
): Promise<UpdateWriteOpResult>

Replace a document on MongoDB.

stats(options?: { scale: number; }): Promise<CollStats>

Get all the collection statistics.

updateMany(
query: ObjectLiteral,
update: ObjectLiteral,
options?: { upsert?: boolean; w?: any; wtimeout?: number; j?: boolean; },
): Promise<UpdateWriteOpResult>

Update multiple documents on MongoDB.

updateOne(
query: ObjectLiteral,
update: ObjectLiteral,
options?: ReplaceOneOptions,
): Promise<UpdateWriteOpResult>

Update a single document on MongoDB.