我正在使用词典.在.insert()之后有"_t"和"_v".这里有两篇文章谈到序列化转换为JSON然后BSON.我正在使用MongoDB的驱动程序v2.4.3,
mCollection.InsertOne(x);
IMongoCollection<myDoc> mCollection = Db.GetCollection<myDoc>("whatever");
Run Code Online (Sandbox Code Playgroud)
如果我做JSON-to-BSON,它抱怨无法将BsonDocument转换为myDoc.切换到IMongoCollection<BsonDocument> mCollection = Db.GetCollection<BsonDocument>("whatever");仍然得到_t和_v.
如何避免_t和_v?
这是我的数据类型和利用率代码:
public class myObjForDictionary
{
//...
}
public class myDoc
{
// ... some other elements, then Dictionary
public Dictionary<string, object> myDictionary { get; set; }
}
// to instantiate the
class myClass
{
// define MongoDB connection, etc.
// instantiate myDoc and populate data
var x = new myDoc
{
//...
myDictionary = new Dictionary<string, object>
{
{ "type", "something" },
{ "Vendor", new object[0] },
{ "obj1", //data for myObjForDictionary
}
};
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2047 次 |
| 最近记录: |