DBCollection constructor

DBCollection({
  1. required String name,
  2. required Db db,
})

Constructor to initialize the name of the collection and the db instance.

When initialized, the constructor checks if the collection exists in the database, and creates it if it does not already exist.

Implementation

DBCollection({required this.name, required this.db}) {
  db.getCollectionNames().then((coll) async {
    if (!coll.contains(name)) {
      await db.createCollection(name);
    }
  });
}