ctx.dataSourceManager
The Data Source Manager (DataSourceManager instance) is used to manage and access multiple data sources (e.g., the main database main, logging database logging, etc.). It is used when multiple data sources exist or when cross-data source metadata access is required.
Use Cases
Note: If you are only operating on the current data source, prioritize using
ctx.dataSource. Usectx.dataSourceManageronly when you need to enumerate or switch between data sources.
Type Definition
Relationship with ctx.dataSource
Examples
Get a Specific Data Source
Access Collection Metadata Across Data Sources
Get Field Definition by Full Path
Iterate Through All Data Sources
Dynamically Select Data Source Based on Variables
Notes
- The path format for
getCollectionFieldisdataSourceKey.collectionName.fieldPath, where the first segment is the data source key, followed by the collection name and the field path. getDataSource(key)returnsundefinedif the data source does not exist; it is recommended to perform a null check before use.addDataSourcewill throw an exception if the key already exists;upsertDataSourcewill either overwrite the existing one or add a new one.
Related
- ctx.dataSource: Current data source instance
- ctx.collection: Collection associated with the current context
- ctx.collectionField: Collection field definition for the current field

