I am using the latest version of C # -driver for MongoDB. I added the following code to my camelcase serialization program:
var camelCaseConvention = new ConventionPack { new CamelCaseElementNameConvention() }; ConventionRegistry.Register("CamelCase", camelCaseConvention, type => true);
However, I get problems when trying to request documents after using serialization. For instance:
var query = _collection.AsQueryable<TimeSeries>(); Console.WriteLine(query.ToJson());
returns the following:
{ "_id" : ObjectId("54af0e848c27be15fc47a0d9"), "Name" : null, "Time" : null }
ie, all properties seem to be null, except for id.
The object is ordered correctly, the field names are in the camel case ("name" and "time"), and each document contains the correct data ("name": "Test 1" and "time": 2014).
It seems that the problem is that the query function does not understand that the fields are in camelcase and therefore returns null. Therefore, I cannot deserialize any objects.
Is there any way to avoid this error?
source share