Tag: bson

将BSON转换为有效的JSON

BsonDocument.ToJson()方法返回无效的JSON,因为ObjectID()和ISODate不是有效的JSON。 从仲裁BSON文档中获取有效JSON的最佳方法是什么?

使用C#BsonArray在MongoDB集合中插入TextMany文档

如何使用C#中的InsertMany()MongoDB方法在Single语句中插入多个文档 我的MongoDB数据库和连接 IMongoClient _client; IMongoDatabase _database; _client = new MongoClient(); _database = _client.GetDatabase(“test”); var collection = _database.GetCollection(“EmpInfo”); 我有一个collections–BsonArray var EmpInfoArray = new BsonArray { new BsonDocument { {“EmpID”, “100”}, {“EmpName”, “John”}, {“EmpMobile”, new BsonArray { new BsonDocument { {“MobNumber”, “55566610”}, {“IsPreferred”, true}, {“IsLive”, false} }, new BsonDocument { {“MobNumber”, “55566611”}, {“IsPreferred”, true}, {“IsLive”, true} }, […]

字典 -to-BsonDocument转换省略_t字段

我正在使用ToBsonDocument扩展方法来转换这个字典: var dictionary = new Dictionary {{“person”, new Dictionary {{“name”, “John”}}}}; var document = dictionary.ToBsonDocument(); 这是结果文件: { “person” : { “_t” : “System.Collections.Generic.Dictionary`2[System.String,System.Object]”, “_v” : { “name” : “John” } } } 有没有办法摆脱这些_t / _v的东西? 我希望生成的文档看起来像这样: { “person” : { “name” : “John” } } UPD:我在DictionaryGenericSerializer中找到了代码: if (nominalType == typeof(object)) { var actualType = value.GetType(); […]

mongodb c#如何使用BSON文档

我花了很多时间寻找答案……这在PHP中很容易,但我不能把它放在C#中(我是C#和mongo的新手……)我正在尝试迭代存储文档的所有级别。 该文件如下: { “_id” : ObjectId(“51f90101853bd88971ecdf27”), “fields” : [{ “ID” : ObjectId(“51fd09498b080ee40c00514e”), “NAME” : “ID”, “TYPE” : “Text” }, { “ID” : ObjectId(“51fd09a68b080ee40c0064db”), “NAME” : “Title”, “TYPE” : “Text” }, { “ID” : ObjectId(“51fd09b28b080ee40c004d31”), “NAME” : “Start Date”, “TYPE” : “Date” }, { “ID” : ObjectId(“51fd09c28b080ee40c007f2e”), “NAME” : “Long Description”, “TYPE” : “Memo” }], “name” […]