Mongo C# Driver: Deserialize BsonValue

前端 未结 4 1066
忘掉有多难
忘掉有多难 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条回答
  •  死守一世寂寞
    2021-02-05 16:32

    Here is how it can be done:

    using MongoDB.Bson.Serialization;
    
    MongoServer srv = MongoServer.Create(myConnStr);
    BsonDocument doc = srv["db"]["products"].FindOneById(ObjectId.Parse("abcdef01234"));
    BsonValue dimVal = doc["Dimensions"];
    List d = BsonSerializer.Deserialize>(dimVal.ToJson());
    

提交回复
热议问题