Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB evaluation query expressions in C# driver

Tags:

c#

.net

mongodb

I stumbled upon the $expr feature in MongoDB 3.6. I want to use it in conjunction with change streams to only receive updates if property A of the updated document is greater than property B.

db.items.find({ $expr: { $gt: [ "$A" , "$B" ] } });

Is the feature implemented in the C# driver? I'm using the Builders to build the pipeline filters, but didn't find the appropriate methods for the $expr operator.

like image 369
aseipel Avatar asked Nov 07 '22 06:11

aseipel


1 Answers

I've recently come across this too, I ended up going for the follow option of just writing out the query as a string for the match pipeline

var cursor = _collection.Watch(PipelineDefinition<YourType, YourType>.Create(
  new[]
  {
    PipelineStageDefinitionBuilder.Match<BsonDocument>(@"{ $expr: { $eq: [ ""$A"" , ""$B"" ] }  }")
  }));
like image 162
Kevin Smith Avatar answered Nov 15 '22 07:11

Kevin Smith