您好我正在尝试插入 mongoDB 2 对象。当我插入 1 个对象时,它工作正常,
private void Query<TO>(TO o)
{
const string connectionString = "mongodb://localhost";
var client = new MongoClient(connectionString);
var server = client.GetServer();
var database = server.GetDatabase("test");
var collection = database.GetCollection<TO>(o.GetType().Name + "s");
collection.Insert(o);
}
但是当我尝试插入 2 个对象时,BSON 驱动程序会出错
private void Query<TO, TK, TV>(TO o, Dictionary<TK, TV> ExtraFields)
{
const string connectionString = "mongodb://localhost";
var client = new MongoClient(connectionString);
var server = client.GetServer();
var database = server.GetDatabase("test");
var collection = database.GetCollection<Object[]>(o.GetType().Name + "s");
collection.Insert(new List<object>
{
o,
ExtraFields
});
}
我得到的错误是
{"Serializer EnumerableSerializer 期望 ArraySerializationOptions 类型的序列化选项,而不是 DocumentSerializationOptions。"}
谢谢