Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MongoRepository<Entity>

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

Type parameters

Hierarchy

Index

Properties

manager

Entity Manager used by this repository.

metadata

metadata: EntityMetadata

Entity metadata of the entity current repository manages.

Optional queryRunner

queryRunner: QueryRunner

Query runner provider used for this repository.

Accessors

target

  • get target(): Function | string
  • Returns object that is managed by this repository. If this repository manages entity from schema, then it returns a name of that schema instead.

    Returns Function | string

Methods

aggregate

aggregateEntity

bulkWrite

clear

  • clear(): Promise<void>

collectionIndexExists

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

collectionIndexInformation

  • collectionIndexInformation(options?: object): Promise<any>

collectionIndexes

  • collectionIndexes(): Promise<any>

count

create

  • create(): Entity
  • create(entityLikeArray: DeepPartial<Entity>[]): Entity[]
  • create(entityLike: DeepPartial<Entity>): Entity

createCollectionIndex

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

createCollectionIndexes

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

createCursor

createEntityCursor

  • 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.

    Parameters

    Returns Cursor<Entity>

createQueryBuilder

decrement

delete

  • Deletes entities by a given criteria. Unlike save method executes a primitive operation without cascades, relations and other operations included. Executes fast and efficient DELETE query. Does not check if entity exist in the database.

    Parameters

    Returns Promise<DeleteResult>

deleteMany

deleteOne

distinct

  • distinct(key: string, query: ObjectLiteral, options?: object): Promise<any>

dropCollectionIndex

dropCollectionIndexes

  • dropCollectionIndexes(): Promise<any>

find

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

findAndCount

  • 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).

    Parameters

    Returns Promise<[Entity[], number]>

findByIds

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

findOne

findOneAndDelete

findOneAndReplace

findOneAndUpdate

findOneOrFail

geoHaystackSearch

geoNear

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

getId

  • getId(entity: Entity): any

group

  • group(keys: Object | Array<any> | Function | Code, condition: Object, initial: Object, reduce: Function | Code, finalize: Function | Code, command: boolean, options?: object): Promise<any>
  • Run a group command across a collection.

    Parameters

    • keys: Object | Array<any> | Function | Code
    • condition: Object
    • initial: Object
    • reduce: Function | Code
    • finalize: Function | Code
    • command: boolean
    • Optional options: object

    Returns Promise<any>

hasId

  • hasId(entity: Entity): boolean

increment

initializeOrderedBulkOp

initializeUnorderedBulkOp

insert

  • Inserts a given entity into the database. Unlike save method executes a primitive operation without cascades, relations and other operations included. Executes fast and efficient INSERT query. Does not check if entity exist in the database, so query will fail if duplicate entity is being inserted.

    Parameters

    Returns Promise<InsertResult>

insertMany

insertOne

isCapped

  • isCapped(): Promise<any>

listCollectionIndexes

mapReduce

  • 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.

    Parameters

    • map: Function | string
    • reduce: Function | string
    • Optional options: MapReduceOptions

    Returns Promise<any>

merge

  • merge(mergeIntoEntity: Entity, ...entityLikes: DeepPartial<Entity>[]): Entity

parallelCollectionScan

preload

  • preload(entityLike: DeepPartial<Entity>): Promise<Entity | undefined>
  • Creates a new entity from the given plan javascript object. If entity already exist in the database, then it loads it (and everything related to it), replaces all values with the new ones from the given object and returns this new entity. This new entity is actually a loaded from the db entity with all properties replaced from the new object.

    Note that given entity-like object must have an entity id / primary key to find entity by. Returns undefined if entity with given id was not found.

    Parameters

    Returns Promise<Entity | undefined>

query

  • query(query: string, parameters?: any[]): Promise<any>
  • Raw SQL query execution is not supported by MongoDB. Calling this method will return an error.

    Parameters

    • query: string
    • Optional parameters: any[]

    Returns Promise<any>

reIndex

  • 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.

    Returns Promise<any>

remove

  • remove(entities: Entity[], options?: RemoveOptions): Promise<Entity[]>
  • remove(entity: Entity, options?: RemoveOptions): Promise<Entity>

rename

  • rename(newName: string, options?: object): 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.

    Parameters

    • newName: string
    • Optional options: object
      • Optional dropTarget?: boolean

    Returns Promise<Collection<any>>

replaceOne

save

  • save<T>(entities: T[], options: SaveOptions & object): Promise<T[]>
  • save<T>(entities: T[], options?: SaveOptions): Promise<(T & Entity)[]>
  • save<T>(entity: T, options: SaveOptions & object): Promise<T>
  • save<T>(entity: T, options?: SaveOptions): Promise<T & Entity>

stats

  • stats(options?: object): Promise<CollStats>

update

  • Updates entity partially. Entity can be found by a given conditions. Unlike save method executes a primitive operation without cascades, relations and other operations included. Executes fast and efficient UPDATE query. Does not check if entity exist in the database.

    Parameters

    Returns Promise<UpdateResult>

updateMany

updateOne

Generated using TypeDoc