I searching a way to map the Bson objects defined using readable names ("category") to shorts names ("ct") and limit the space occuped by the items names in the main document base. I have seen this using others Drivers but what about using official Driver. How i can make, where is the best place to define. Can use longnames in queries and retrieve short contents?.
thanks.
The MongoDB C Driver, also known as “libmongoc”, is a library for using MongoDB from C applications, and for writing MongoDB drivers in higher-level languages. It depends on libbson to generate and parse BSON documents, the native data format of MongoDB.
By developing with C# and MongoDB together one opens up a world of possibilities. Console, window, and web applications are all possible. As are cross-platform mobile applications using the Xamarin framework.
MongoDB is a NoSQL database that is open source. MongoDB is available in two editions. One is MongoDB Open Source, which is free as part of the Open-Source Community, but for the other editions, you must pay a License fee. When compared to the free edition, this edition has some advanced features.
Since nobody has actually given the answer to the question, here it is.
With the official driver you can do this by decorating a property name with BsonElement. For example:
public class SomeClass
{
public BsonObjectId Id { get; set; }
[BsonElement("dt")]
public DateTime SomeReallyLongDateTimePropertyName { get; set; }
}
Now the driver will use "dt" as the BSON property name.
However, at this time there is no way to query using the POCO property name. You would need to use "dt" in your queries. There is a separate project that is built on top of the C# driver that provides LINQ style querying capabilities, but I have not tested it to verify if it will do what you are asking.
It's better to keep models clean. And MongoDB.Driver allows to do it outside.
BsonClassMap.RegisterClassMap<SomeClass>(x =>
{
x.AutoMap();
x.GetMemberMap(m => m.SomeReallyLongDateTimePropertyName).SetElementName("dt");
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With