Mapping Id property in mongoDb to c#
<p>I have a nested document stored in MongoDB, such as:</p>

<pre><code>{ 
  _id: 56f19c2663e43f940a7fab69, 
  propA: "some value",
  nestedItem: {
                propB: "nested property",
                leafItem: {
                            id: 1458607372380,
                            leafProp: "a leaf property"
                          }
               }
}
</code></pre>

<p>I am trying to map it to a set of C# classes:</p>

<pre><code>public class FirstLevel {
     public ObjectId _id {get; set;}
     public string propA {get; set;}
     public SecondLevel nestedItem {get; set;}
}

public class SecondLevel {
     public string propB {get; set;}
     public ThirdLevel leafItem {get; set;}
}

[BsonIgnoreExtraElements]
public class ThirdLevel {
     public long id {get; set;}
     public string leafProp {get; set;}
}
</code></pre>

<p>If I remove the 'BsonIgnoreExtraElements', it gives an error that <code>An error occurred while deserializing the leafItem property of class ConsoleApplication1.SecondLevel: Element 'id' does not match any field or property of class ConsoleApplication1.ThirdLevel.</code></p>

<p>If I keep the ignore elements, it populates 0 in the id.</p>

<p>If I have a member for [BsonExtraElements], it does show id as a property and also shows the value.</p>

<p>To give a background on the id value, I am creating this JSON structure in a client browser application, and using new Date().valueOf() to get a unique number for id.</p>

<p>When I view the documents in MongoVue, I see that the type is recognized as Double, and the bson extra elements member also shows it as a double type.</p>

<p>I am simply trying to get the value into the class member. Any help will be appreciated.</p>

<p>Thanks</p>