Convert string into MongoDB BsonDocument

后端 未结 3 940
误落风尘
误落风尘 2020-12-02 15:37

I have a long string in JSON format, and I want to convert it into a BSONDocument for insertion into a MongoDB database. How do I do the conversion? I\'m using the officia

相关标签:
3条回答
  • 2020-12-02 16:00

    Using Version 2.1 of MongoDB's .NET library

    string json = "{'foo' : 'bar' }";
    var document = new BsonDocument();
    document.Add(BsonDocument.Parse(json));
    
    0 讨论(0)
  • 2020-12-02 16:03
    string json = "{ 'foo' : 'bar' }";  
    BsonDocument document = BsonDocument.Parse(json);
    
    0 讨论(0)
  • 2020-12-02 16:06

    The answer is:

    string json = "{ 'foo' : 'bar' }";
    MongoDB.Bson.BsonDocument document
        = MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonDocument>(json);
    
    0 讨论(0)
提交回复
热议问题