4 / 4
Jul 2024

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?

22 days later