Debug MongoDB requests using the C # v2 API

Can I serialize FilterDefinition<T> to json string to see what is being built under the hood? Or only through the logs and more detailed database profiler settings?

+5
source share
1 answer

Yes, FilterDefinition has a Render method. If you have access to the collection you are using, you can do the following.

 var renderedFilter = definition.Render(collection.DocumentSerializer, collection.Settings.SerializerRegistry); 

It will display a BsonDocument that you can use ToString () if you want JSON.

+8
source

All Articles