How I can append $comment when working with FilterDefinition


I have a question regarding to Definitions and Builders. How I can append $comment when working with FilterDefinition like FilterDefinition filter = Builders.Filter.Eq(x => x.Id, entity.Id) where TEntity are my POCOs objects?

Hi @Harnier, and welcome to the forum!

You can try to append the comment as an option after the filter, for example:

var filter = Builders<Test>.Filter.Eq(x=> x.Foo, "baz");

FindOptions MyFindOptions = new FindOptions();
MyFindOptions.Comment = "token-001";

var document = collection.Find(filter, MyFindOptions).First();


Hi @wan,
Thanks for the quick response. I should have been more specific when I posted my question. As you explained earlier, working with reading operations is pretty straight forward.
However my question is regarding to write operations like update and delete. Let’s assume I have this method to update multiple documents:

protected OperationResult<UpdateResult> UpdateMany(FilterDefinition<TEntity> filter, UpdateDefinition<TEntity> update,
            UpdateOptions updateOptions = null, long? aggregateVersion = null)
   var result = Collection.UpdateMany(filter, update, updateOptions ?? new UpdateOptions());


   return result.AsSuccessResult();

In this case UpdateOptions class doesn’t have support for the Comment property like FindOptionsBase class has. In a previous post you mentioned that there is a ticket DRIVERS-742 to add support to this
but I don’t have access to see its status. Is it already resolved? If the answer is no, the only workaround for updates is the $comment query operator?