API 参考
    正在准备搜索索引...

    类 MongoRepository<Entity>

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

    类型参数

    层级 (查看层级一览)

    索引

    构造函数

    属性

    Entity Manager used by this repository.

    queryRunner?: QueryRunner

    Query runner provider used for this repository.

    Entity target that is managed by this repository. If this repository manages entity from schema, then it returns a name of that schema instead.

    访问器

    • get metadata(): EntityMetadata

      Entity metadata of the entity current repository manages.

      返回 EntityMetadata

    方法

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

      参数

      返回 AggregationCursor<Entity>

    • Clears all the data from the given table/collection (truncates/drops it).

      Note: this method uses TRUNCATE and may not work as you expect in transactions on some platforms.

      返回 Promise<void>

    • Retrieve all the indexes on the collection.

      返回 Promise<any>

    • Retrieve all the indexes on the collection.

      参数

      • indexes: string | string[]

      返回 Promise<boolean>

    • Retrieves this collections index info.

      参数

      • 可选options: { full: boolean }

      返回 Promise<any>

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

      参数

      返回 Promise<number>

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

      参数

      返回 Promise<number>

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

      参数

      返回 Promise<number>

    • Creates a new entity instance.

      返回 Entity

    • Creates new entities and copies all entity properties from given objects into their new entities. Note that it copies only properties that are present in entity schema.

      参数

      返回 Entity[]

    • Creates a new entity instance and copies all entity properties from this object into a new entity. Note that it copies only properties that are present in entity schema.

      参数

      返回 Entity

    • Creates an index on the db and collection.

      参数

      返回 Promise<string>

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

      参数

      返回 Promise<string[]>

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

      类型参数

      • T = any

      参数

      返回 FindCursor<T>

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

      参数

      返回 FindCursor<Entity>

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

      参数

      返回 SelectQueryBuilder<Entity>

    • Decrements some column by provided value of the entities matched given conditions.

      参数

      返回 Promise<UpdateResult>

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

      参数

      返回 Promise<DeleteResult>

    • Delete multiple documents on MongoDB.

      参数

      返回 Promise<DeleteResult>

    • Delete a document on MongoDB.

      参数

      返回 Promise<DeleteResult>

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

      参数

      返回 Promise<any>

    • Drops an index from this collection.

      参数

      返回 Promise<any>

    • Drops all indexes from the collection.

      返回 Promise<any>

    • Checks whether any entity exists that matches the given options.

      参数

      返回 Promise<boolean>

      use exists method instead, for example:

      .exists()

    • Checks whether any entity exists that matches the given options.

      参数

      返回 Promise<boolean>

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

      参数

      • 可选options: MongoFindManyOptions<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).

      参数

      • where: any

      返回 Promise<[Entity[], number]>

    • Finds entities that match given find options or conditions.

      参数

      • where: any

      返回 Promise<Entity[]>

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

      参数

      • ids: any[]
      • 可选options: any

      返回 Promise<Entity[]>

      use findBy method instead in conjunction with In operator, for example:

      .findBy({ id: In([1, 2, 3]) })

    • Finds first entity that matches given find options.

      参数

      • options: MongoFindOneOptions<Entity>

      返回 Promise<null | Entity>

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

      参数

      返回 Promise<null | Document>

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

      参数

      返回 Promise<null | Document>

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

      参数

      返回 Promise<null | Document>

    • Finds first entity that matches given WHERE conditions.

      参数

      • where: any

      返回 Promise<null | Entity>

    • Finds entity that matches given id.

      参数

      返回 Promise<null | Entity>

      use findOneBy method instead in conjunction with In operator, for example:

      .findOneBy({ id: 1 // where "id" is your primary column name })

    • Finds first entity that matches given where condition. If entity was not found in the database - rejects with error.

      参数

      • where: any

      返回 Promise<Entity>

    • Finds first entity by a given find options. If entity was not found in the database - rejects with error.

      参数

      返回 Promise<Entity>

    • Gets entity mixed id.

      参数

      返回 any

    • Checks if entity has an id. If entity composite compose ids, it will check them all.

      参数

      返回 boolean

    • Increments some column by provided value of the entities matched given conditions.

      参数

      返回 Promise<UpdateResult>

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

      参数

      返回 OrderedBulkOperation

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

      参数

      返回 UnorderedBulkOperation

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

      参数

      返回 Promise<InsertResult>

    • Returns if the collection is a capped collection.

      返回 Promise<any>

    • Get the list of all indexes information for the collection.

      参数

      返回 ListIndexesCursor

    • Merges multiple entities (or entity-like objects) into a given entity.

      参数

      返回 Entity

    • Creates a new entity from the given plain 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.

      参数

      返回 Promise<undefined | Entity>

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

      参数

      • query: string
      • 可选parameters: any[]

      返回 Promise<any>

    • Recovers all given entities in the database.

      类型参数

      • T extends
            | ObjectLiteral
            | Map<unknown, unknown>
            | Set<unknown>
            | any[]
            | { [key: string]: any }

      参数

      返回 Promise<T[]>

    • Recovers all given entities in the database.

      类型参数

      • T extends
            | ObjectLiteral
            | Map<unknown, unknown>
            | Set<unknown>
            | any[]
            | { [key: string]: any }

      参数

      返回 Promise<(T & Entity)[]>

    • Recovers a given entity in the database.

      类型参数

      • T extends
            | ObjectLiteral
            | Map<unknown, unknown>
            | Set<unknown>
            | any[]
            | { [key: string]: any }

      参数

      返回 Promise<T>

    • Recovers a given entity in the database.

      类型参数

      • T extends
            | ObjectLiteral
            | Map<unknown, unknown>
            | Set<unknown>
            | any[]
            | { [key: string]: any }

      参数

      返回 Promise<T & Entity>

    • Removes a given entities from the database.

      参数

      返回 Promise<Entity[]>

    • Removes a given entity from the database.

      参数

      返回 Promise<Entity>

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

      参数

      • newName: string
      • 可选options: { dropTarget?: boolean }

      返回 Promise<Collection<Document>>

    • Replace a document on MongoDB.

      参数

      返回 Promise<Document | UpdateResult>

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

      参数

      返回 Promise<UpdateResult>

    • Saves all given entities in the database. If entities do not exist in the database then inserts, otherwise updates.

      类型参数

      • T extends
            | ObjectLiteral
            | Map<unknown, unknown>
            | Set<unknown>
            | any[]
            | { [key: string]: any }

      参数

      返回 Promise<T[]>

    • Saves all given entities in the database. If entities do not exist in the database then inserts, otherwise updates.

      类型参数

      • T extends
            | ObjectLiteral
            | Map<unknown, unknown>
            | Set<unknown>
            | any[]
            | { [key: string]: any }

      参数

      返回 Promise<(T & Entity)[]>

    • Saves a given entity in the database. If entity does not exist in the database then inserts, otherwise updates.

      类型参数

      • T extends
            | ObjectLiteral
            | Map<unknown, unknown>
            | Set<unknown>
            | any[]
            | { [key: string]: any }

      参数

      返回 Promise<T>

    • Saves a given entity in the database. If entity does not exist in the database then inserts, otherwise updates.

      类型参数

      • T extends
            | ObjectLiteral
            | Map<unknown, unknown>
            | Set<unknown>
            | any[]
            | { [key: string]: any }

      参数

      返回 Promise<T & Entity>

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

      参数

      返回 Promise<UpdateResult>

    • Records the delete date of all given entities.

      类型参数

      • T extends
            | ObjectLiteral
            | Map<unknown, unknown>
            | Set<unknown>
            | any[]
            | { [key: string]: any }

      参数

      返回 Promise<T[]>

    • Records the delete date of all given entities.

      类型参数

      • T extends
            | ObjectLiteral
            | Map<unknown, unknown>
            | Set<unknown>
            | any[]
            | { [key: string]: any }

      参数

      返回 Promise<(T & Entity)[]>

    • Records the delete date of a given entity.

      类型参数

      • T extends
            | ObjectLiteral
            | Map<unknown, unknown>
            | Set<unknown>
            | any[]
            | { [key: string]: any }

      参数

      返回 Promise<T>

    • Records the delete date of a given entity.

      类型参数

      • T extends
            | ObjectLiteral
            | Map<unknown, unknown>
            | Set<unknown>
            | any[]
            | { [key: string]: any }

      参数

      返回 Promise<T & Entity>

    • Get all the collection statistics.

      参数

      返回 Promise<CollStats>

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

      参数

      • criteria:
            | string
            | number
            | string[]
            | Date
            | ObjectId
            | number[]
            | Date[]
            | ObjectId[]
            | FindOptionsWhere<Entity>
      • partialEntity: QueryDeepPartialEntity<Entity>

      返回 Promise<UpdateResult>

    • Inserts a given entity into the database, unless a unique constraint conflicts then updates the entity Unlike save method executes a primitive operation without cascades, relations and other operations included. Executes fast and efficient INSERT ... ON CONFLICT DO UPDATE/ON DUPLICATE KEY UPDATE query.

      参数

      返回 Promise<InsertResult>