转换成字符串的MongoDB BsonDocument [英] Convert string into MongoDB BsonDocument

查看:3410
本文介绍了转换成字符串的MongoDB BsonDocument的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JSON格式的长字符串,我想将其转换成一个BSONDocument插入到MongoDB数据库。我该怎么做转换?我使用的是官方的C#驱动程序。

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 official C# driver.

推荐答案

答案是:

string json = "{ 'foo' : 'bar' }";
MongoDB.Bson.BsonDocument document
    = MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonDocument>(json);

这篇关于转换成字符串的MongoDB BsonDocument的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆