toListParams static method
Converts a list of DBModel instances to a list of maps for MongoDB operations.
The toListParams method takes a list of DBModel instances and asynchronously converts each model to a map using the toParams method. The resulting list of maps can be used for batch database operations.
The optional db
parameter can be passed to provide the database context if needed during serialization.
Example:
List<DBModel> models = [model1, model2, model3];
List<Map<String, Object?>> serializedModels = await DBModel.toListParams(models);
Returns a Future containing a List of maps representing the serialized models.
Implementation
static Future<List<Map<String, Object?>>> toListParams(List<DBModel> list,
{Db? db}) async {
var res = <Map<String, Object?>>[];
for (var element in list) {
res.add(await element.toParams(db: db));
}
return res;
}