Mongo C# Driver: Deserialize BsonValue

前端 未结 4 1119
忘掉有多难
忘掉有多难 2021-02-05 15:42

I have a document in mongodb that is structured similar to this:

{
  \"_id\": \"abcdef01234\",
  \"Name\": \"Product A\",
  \"Dimensions\": [
    {
      \"Heigh         


        
4条回答
  •  萌比男神i
    2021-02-05 16:22

    Try this:

    public class Product
    {
       [BsonId]
       public ObjectId Id { get; set; }
    
       public string Name{ get; set; }
    
       public List Dimensions{ get; set; }
    }
    
    public class DimensionDoc
    {
       public int Height { get; set; }
       public int Width { get; set; }
    
    }
    
    Product product = srv["db"]["products"].FindOneByIdAs(ObjectId.Parse("abcdef01234"));
    

    product.Dimensions will now contain the List<> you need.

提交回复
热议问题