watchWithFilter method

Stream watchWithFilter(
  1. Map<String, dynamic>? filter
)

Watches a collection. The provided BSON document will be used as a match expression filter on the change events coming from the stream.

Implementation

Stream watchWithFilter(Map<String, dynamic>? filter) {
  // convert 'QuerySelector' into map, too
  filter?.forEach((key, value) {
    if (value is QueryOperator) {
      filter[key] = value.values;
    }
  });

  var fixFilter = <String, dynamic>{};
  filter?.forEach((key, value) {
    fixFilter["fullDocument.$key"] = value;
  });

  if (kIsWeb) {
    FlutterMongoRealm.setupWatchCollection(collectionName, databaseName,
        filter: BsonDocument(fixFilter).toJson());
  }

  var stream = FlutterMongoRealm.watchCollection(
    collectionName: this.collectionName,
    databaseName: this.databaseName,
    filter: BsonDocument(fixFilter).toJson(),
  );

  return stream;
}