DBCollectionFree constructor
DBCollectionFree({})
Constructor to initialize the collection with required parameters.
Creates a new database collection instance and automatically handles:
- Collection registration in the global list
- Collection creation if it doesn't exist in the database
- Index renewal and management
Parameters:
name
- The name of the MongoDB collectiondb
- The MongoDB database instanceform
- The form definition with field validatorsindexes
- Optional map of database indexes to create
Example:
final userCollection = UserCollection(
name: 'users',
db: mongoDb,
form: userForm,
indexes: {'email': DBIndex(key: 'email', unique: true)},
);
Implementation
DBCollectionFree({
required this.name,
required this.db,
required this.form,
this.indexes = const {},
}) {
_allCollectionFree.add(this);
db.getCollectionNames().then((coll) async {
if (!coll.contains(name)) {
await db.createCollection(name);
}
_renewIndexes();
});
}