DBCollection class abstract

An abstract class representing a MongoDB collection with utility methods.

The DBCollection class provides an abstraction over a MongoDB collection, offering various methods to interact with the database, such as checking for the existence of a document by its ID, updating fields, and more. This class is meant to be extended by other classes for more specific collection implementations.

Constructors

DBCollection({required String name, required Db db})
Constructor to initialize the name of the collection and the db instance.

Properties

collection → DbCollection
Provides direct access to the underlying MongoDB collection.
no setter
db ↔ Db
The MongoDB database instance.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
isEmpty Future<bool>
Checks if the collection is empty.
no setter
isNotEmpty Future<bool>
Checks if the collection is not empty.
no setter
name String
The name of the MongoDB collection.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

copy(String id) Future<void>
Creates a copy of a document by its ID and inserts it as a new document.
delete(String id) Future<bool>
Deletes a document from the collection by its ID.
deleteAll() Future<bool>
Deletes all documents from the collection. Returns true if the deletion was successful, otherwise false. You have to be careful when using this method, as it will delete all documents in the collection.
exist(String field, Object value) Future<bool>
Checks if a document with the specified field and value exists in the collection.
existId(String idField) Future<bool>
Checks if a document with the given ID exists in the collection.
getCount({String? field, Object? value, Map<String, Object?>? filter}) Future<int>
Retrieves the count of documents in the collection based on the specified filters.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
updateAllForField({required String field, required Object? value, required Map<String, Object?>? filter}) Future<void>
Updates a specific field for all documents that match the given filter.
updateField(String id, String field, Object? value) Future<void>
Updates a specific field of a document by its ID.
updateFields(String id, Map<String, dynamic> fields) Future<void>
Updates multiple fields of a document by its ID.

Operators

operator ==(Object other) bool
The equality operator.
inherited