[C# | MongoDB Driver 2.0+] Element 'key' does not match any field or property of class
C# MongoDB Driver 2.0+를 사용하다 발생한 "Element 'key' does not match any field or property of class" 오류를 처리하는 방법에 대해 알아봅니다.
1. 현상.
FindOneAndUpdate 작업에 IsUpsert 옵션을 true로 설정해 둔 채 작업을 수행하다 에러가 발생했습니다.
신규 Insert시에는 문제가 없었으나 Update시에 발생한 문제였으며 예외 메시지는 다음과 같았습니다.
Element '{FIELD}' does not match any field or property of class {PROJECT}.MongoDB.Documents.{CLASS}.
2. 수정.
클래스 선언 위에 "[BsonIgnoreExtraElements]"를 추가해 줍니다.
이후 FindOneAndUpdate 작업을 다시 수행하면 정상적으로 수행 됩니다.
References: Element 'Id' does not match any field or property of class
Element 'Id' does not match any field or property of class
I got the result from the collection in MongoDB, the structure is the same as below [DataContract] public class Father { [BsonId] [DataMember] public MongoDB.Bson.ObjectId _id { get; s...
stackoverflow.com