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

    Entity manager supposed to work with any entity, automatically find its repository and call its methods, whatever entity type are you passing.

    This implementation is used for MongoDB driver which has some specifics in its EntityManager.

    层级 (查看层级一览)

    索引

    构造函数

    属性

    "@instanceof": symbol
    connection: DataSource

    Connection used by this entity manager.

    plainObjectToEntityTransformer: PlainObjectToNewEntityTransformer

    Plain to object transformer used in create and merge operations.

    queryRunner?: QueryRunner

    Custom query runner to be used for operations in this entity manager. Used only in non-global entity manager.

    repositories: Map<EntityTarget<any>, Repository<any>>

    Once created and then reused by repositories. Created as a future replacement for the #repositories to provide a bit more perf optimization.

    treeRepositories: TreeRepository<any>[]

    Once created and then reused by repositories.

    访问器

    • get mongoQueryRunner(): MongoQueryRunner

      返回 MongoQueryRunner

    方法

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

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

      类型参数

      • Entity

      参数

      返回 Promise<void>

    • Retrieve all the indexes on the collection.

      类型参数

      • Entity

      参数

      返回 Promise<Document>

    • Retrieve all the indexes on the collection.

      类型参数

      • Entity

      参数

      返回 Promise<boolean>

    • Retrieves this collections index info.

      类型参数

      • Entity

      参数

      返回 Promise<any>

    • Converts FindManyOptions to mongodb query.

      类型参数

      • Entity

      参数

      返回 undefined | ObjectLiteral

    • Converts FindOneOptions to mongodb query.

      类型参数

      • Entity

      参数

      • optionsOrConditions: undefined | MongoFindOneOptions<Entity> | Partial<Entity>

      返回 undefined | ObjectLiteral

    • Converts FindOptions into mongodb order by criteria.

      参数

      返回 ObjectLiteral

    • Converts FindOptions into mongodb select by criteria.

      参数

      返回 any

    • Ensures given id is an id for query.

      参数

      返回 ObjectLiteral

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

      类型参数

      • Entity

      参数

      返回 Promise<number>

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

      类型参数

      • Entity

      参数

      返回 Promise<number>

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

      类型参数

      • Entity

      参数

      返回 Promise<number>

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

      类型参数

      • Entity
      • EntityLike

      参数

      返回 Entity

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

      类型参数

      • Entity
      • EntityLike

      参数

      返回 Entity[]

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

      类型参数

      • Entity

      参数

      返回 Promise<string[]>

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

      类型参数

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

      类型参数

      • Entity

      参数

      返回 FindCursor<Entity>

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

      类型参数

      参数

      • entityClass: EntityTarget<Entity>
      • conditions: any
      • propertyPath: string
      • value: string | number

      返回 Promise<UpdateResult>

    • Deletes entities by a given conditions. 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.

      类型参数

      • Entity

      参数

      返回 Promise<DeleteResult>

    • Delete multiple documents on MongoDB.

      类型参数

      • Entity

      参数

      返回 Promise<DeleteResult>

    • Delete a document on MongoDB.

      类型参数

      • Entity

      参数

      返回 Promise<DeleteResult>

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

      类型参数

      • Entity

      参数

      返回 Promise<any>

    • Drops an index from this collection.

      类型参数

      • Entity

      参数

      返回 Promise<any>

    • Drops all indexes from the collection.

      类型参数

      • Entity

      参数

      返回 Promise<any>

    • 类型参数

      • Entity

      参数

      返回 Promise<Entity[]>

    • Finds entities that match given find options or conditions.

      类型参数

      • Entity

      参数

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

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

      类型参数

      • Entity

      参数

      返回 Promise<null | Entity>

    • 类型参数

      • Entity

      参数

      返回 void

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

      类型参数

      • Entity

      参数

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

    • Finds entities that match given where conditions.

      类型参数

      • Entity

      参数

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

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

      类型参数

      • Entity

      参数

      返回 Promise<Entity[]>

      use findBy method instead.

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

      类型参数

      • Entity

      参数

      返回 Promise<null | Entity>

    • Finds first entity that matches given WHERE conditions.

      类型参数

      • Entity

      参数

      返回 Promise<null | Entity>

    • Finds entity that matches given id.

      类型参数

      • Entity

      参数

      返回 Promise<null | Entity>

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

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

    • Gets custom entity repository marked with

      类型参数

      • T

      参数

      返回 T

      decorator.

      use Repository.extend to create custom repositories

    • Gets entity mixed id.

      参数

      • entity: any

      返回 any

    • Gets entity mixed id.

      参数

      返回 any

    • Gets repository for the given entity class or name. If single database connection mode is used, then repository is obtained from the repository aggregator, where each repository is individually created for this entity manager. When single database connection is not used, repository is being obtained from the connection.

      类型参数

      参数

      返回 Repository<Entity>

    • Gets tree repository for the given entity class or name. If single database connection mode is used, then repository is obtained from the repository aggregator, where each repository is individually created for this entity manager. When single database connection is not used, repository is being obtained from the connection.

      类型参数

      参数

      返回 TreeRepository<Entity>

    • Checks if entity has an id.

      参数

      • entity: any

      返回 boolean

    • Checks if entity of given schema name has an id.

      参数

      • target: string | Function
      • entity: any

      返回 boolean

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

      类型参数

      参数

      • entityClass: EntityTarget<Entity>
      • conditions: any
      • propertyPath: string
      • value: string | number

      返回 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.

      类型参数

      • Entity

      参数

      返回 OrderedBulkOperation

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

      类型参数

      • Entity

      参数

      返回 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. You can execute bulk inserts using this method.

      类型参数

      • Entity

      参数

      返回 Promise<InsertResult>

    • Returns if the collection is a capped collection.

      类型参数

      • Entity

      参数

      返回 Promise<any>

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

      类型参数

      参数

      返回 Promise<undefined | Entity>

    • Executes raw SQL query and returns raw database results.

      类型参数

      • T = any

      参数

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

      返回 Promise<T>

      Official docs for examples.

    • Recovers all given entities.

      类型参数

      • Entity

      参数

      返回 Promise<Entity[]>

    • Recovers a given entity.

      类型参数

      • Entity

      参数

      返回 Promise<Entity>

    • Recovers all given entities.

      类型参数

      • Entity
      • T

      参数

      返回 Promise<T[]>

    • Recovers a given entity.

      类型参数

      • Entity
      • T

      参数

      返回 Promise<T>

    • Releases all resources used by entity manager. This is used when entity manager is created with a single query runner, and this single query runner needs to be released after job with entity manager is done.

      返回 Promise<void>

    • Removes a given entity from the database.

      类型参数

      • Entity

      参数

      返回 Promise<Entity>

    • Removes a given entity from the database.

      类型参数

      • Entity

      参数

      返回 Promise<Entity>

    • Removes a given entity from the database.

      类型参数

      • Entity

      参数

      返回 Promise<Entity>

    • Removes a given entity from the database.

      类型参数

      • Entity

      参数

      返回 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.

      类型参数

      • Entity

      参数

      返回 Promise<Collection<Document>>

    • Restores entities by a given condition(s). 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. Condition(s) cannot be empty.

      类型参数

      参数

      返回 Promise<UpdateResult>

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

      类型参数

      • Entity

      参数

      返回 Promise<Entity[]>

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

      类型参数

      • Entity

      参数

      返回 Promise<Entity>

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

      类型参数

      • Entity
      • T

      参数

      返回 Promise<T[]>

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

      类型参数

      • Entity
      • T

      参数

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

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

      类型参数

      • Entity
      • T

      参数

      返回 Promise<T>

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

      类型参数

      • Entity
      • T

      参数

      返回 Promise<T & Entity>

    • Records the delete date of entities by a given condition(s). 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. Condition(s) cannot be empty.

      类型参数

      参数

      返回 Promise<UpdateResult>

    • Records the delete date of all given entities.

      类型参数

      • Entity

      参数

      返回 Promise<Entity[]>

    • Records the delete date of a given entity.

      类型参数

      • Entity

      参数

      返回 Promise<Entity>

    • Records the delete date of all given entities.

      类型参数

      • Entity
      • T

      参数

      返回 Promise<T[]>

    • Records the delete date of a given entity.

      类型参数

      • Entity
      • T

      参数

      返回 Promise<T>

    • Get all the collection statistics.

      类型参数

      • Entity

      参数

      返回 Promise<CollStats>

    • Wraps given function execution (and all operations made there) in a transaction. All database operations must be executed using provided entity manager.

      类型参数

      • T

      参数

      返回 Promise<T>

    • Wraps given function execution (and all operations made there) in a transaction. All database operations must be executed using provided entity manager.

      类型参数

      • T

      参数

      • isolationLevel: IsolationLevel
      • runInTransaction: (entityManager: EntityManager) => Promise<T>

      返回 Promise<T>

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

      类型参数

      • Entity

      参数

      返回 Promise<UpdateResult>

    • Creates a new repository instance out of a given Repository and sets current EntityManager instance to it. Used to work with custom repositories in transactions.

      类型参数

      参数

      返回 R