I'm using v0.9 of the official MongoDB driver and i'm trying to read in a collection. I have a field in the database that I don't want to read into my object but I get the following error.
"Unexpected element: Network"
The collection looks like this in the database
Merchants
- _id
- Name
- Description
- Url
- Network
When I read it into C# I want to create an object called Merchant that has all of the same properties, except "Network". How do I do this?
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.
The official MongoDB Node. js driver allows Node. js applications to connect to MongoDB and work with data. The driver features an asynchronous API which allows you to interact with MongoDB using Promises or via traditional callbacks.
Open-Source MongoDb JDBC DriverThe driver binaries can be downloaded as zip file, which you should uncompress. Download the zip, unpack and include the jar files in your classpath. The driver is compatible with Java 11. for any issues with the driver, you can write to us.
There's an "IgnoreExtraElements" option on the BSON serializer which you can enable to prevent that error.
Either set it as an attribute on your Merchant
class:
[BsonIgnoreExtraElements]
public Merchant {
// fields and properties
}
or in code if you're using class maps:
BsonClassMap.RegisterClassMap<Merchant>(cm => {
cm.AutoMap();
cm.SetIgnoreExtraElements(true);
});
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