var pipeline = new EmptyPipelineDefinition<ChangeStreamDocument<BsonDocument>>() .Match(Builders<ChangeStreamDocument<BsonDocument>>.Filter.Gte("fullDocument.temp", 22));
var cursor = collection.Watch(pipeline, options); foreach (var change in cursor.ToEnumerable()) { Console.WriteLine(change.ToJson()); }
I cannot figure out how to set a match criteria on my collections watch method.--For example, in the following I want to get a change stream notification only if temp rises above 22.var client = new MongoClient("mongodb://localhost");var db = client.GetDatabase("test");var collection = db.GetCollection<BsonDocument>("test");var options = new ChangeStreamOptions { FullDocument = ChangeStreamFullDocumentOption.UpdateLookup };var enumerator = collection.Watch(options).ToEnumerable().GetEnumerator();//Doesn't work...//var pipeline = PipelineDefinition<ChangeStreamDocument<BsonDocument>, ChangeStreamDocument<BsonDocument>>.Create(new[] { @"{$match: { 'temp': { $gte: NumberInt(30) } } }" });//var enumerator = collection.Watch(pipeline, options).ToEnumerable().GetEnumerator();while (enumerator.MoveNext()){var next = enumerator.Current;Console.WriteLine(next.FullDocument?.ToJson());}and Documents in the database looks like this:{"name" : "room1","temp" : NumberInt(20)}
{"name" : "room2","temp" : NumberInt(25)}Is this possible to do with the c# driver?
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/3b3eab27-51d8-41c2-ac2b-5ec8af991199%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
PipelineDefinition<ChangeStreamDocument<TestData>, ChangeStreamDocument<TestData>> pipeline = new EmptyPipelineDefinition<ChangeStreamDocument<TestData>>() .Match(Builders<ChangeStreamDocument<TestData>>.Filter.Gte("_id", 10));
...
foreach ( ChangeStreamDocument<TestData> change in coll.Watch( pipeline, watchOptions, cancel.Token ).ToEnumerable() ){ Console.WriteLine( change.OperationType ); Console.WriteLine( change.FullDocument.ToJson() );}
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.