Class: MongoSchemaSync
Defined in: service-core/src/database/MongoSchemaSync.ts:40
Performs structure synchronization of MongoDB collections based on the persistence metadata of model classes.
For each collection associated with a model class the following operations are performed:
- The collection is created if it does not already exist.
- Indexes declared via the
@Indexand@Uniquedecorators are created if missing. - Existing declared indexes whose definition has changed are dropped and re-created.
The synchronization process never drops collections or data, never modifies the built-in _id_ index, and never
drops indexes that are not declared by the model class (e.g. shard keys or manually created indexes).
Constructors
Constructor
new MongoSchemaSync(
db,logger?):MongoSchemaSync
Defined in: service-core/src/database/MongoSchemaSync.ts:44
Parameters
db
Db
logger?
any
Returns
MongoSchemaSync
Methods
resolveCollectionInfo()
resolveCollectionInfo(
clazz):CollectionInfo
Defined in: service-core/src/database/MongoSchemaSync.ts:62
Resolves the entity info of the database collection (or table) that records of the given model class are stored in.
The entity info is resolved using the following rules:
- The nearest class in the inheritance chain (starting with
clazzitself) that specifies an explicit entity info via the@Entity(info)decorator. - Otherwise, the most ancestral class in the inheritance chain that declares its own
@DataStorebinding. This ensures that@ChildEntitysubclasses are stored in the same collection as their parent entity (single collection inheritance). - Otherwise, a new info object containing the snake_case form of the class name.
Parameters
clazz
any
The model class to resolve the collection name for.
Returns
CollectionInfo
synchronize()
synchronize(
entities):Promise<void>
Defined in: service-core/src/database/MongoSchemaSync.ts:98
Synchronizes the structure of all collections associated with the given model classes.
Parameters
entities
Iterable<any>
The list of model classes to synchronize collections for.
Returns
Promise<void>