Setting Default Casing for Fields in C# Driver Builders

I’m using the following C# expression:

Collection.Find(Builders<UserWebHook>.Filter.Eq(x => x.UserId, user))

This generates the following query filter:

{ userId: "abcdef" }

However, I want it to generate:

{ UserId: "abcdef" }

How can I configure the builder to use the desired field naming casing?

Hi @Sergio_Jr ,

Welcome to the MongoDB community forums! What does your model class look like i.e. Are the names of the field matching in the model class to how the field is stored in the database? If not, you might want to look at using Convention packs or attributes like [BsonElement("xyz")] in your model class for the same. Hope that helps.

Thanks,

Rishit.

It worked after adding the class map with only AutoMap invoked, even though the only registered convention was IgnoreExtraElementsConvention . Is it strictly necessary to always add a map for each class?

Hi @Sergio_Jr ,

No, its not strictly necessary to invoke AutoMap. It depends on the conventions being used. This article shares more details into this topic. Let us know if you have any further questions.

Thanks,

Rishit.