Element does not match nay field or property of Class – MongoDb and .net core

Hey everyone,

I ran into the following error today while searching MongoDb for an object:

Element ‘Tags’ does not match any field or property of class X.

The issue was that there were extra fields on the returned document that were not specified on the mapping target object. A bit of Googling revealed that there is a provided attribute that allows you to ignore all extra fields.

Simply add [BsonIgnoreExtraElements] to any relevant model definitions.

Thanks to this stackoverflow post for the lead: https://stackoverflow.com/a/23448987/522859


by

Comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a website or blog at WordPress.com

%d bloggers like this: