这是一个代码段,我将PLC数据插入MongoDB,但我不确定WriteConcern必须在哪里实现?
var connectionString = "mongodb://10.52.124.186:27017/";
// Establish connection from the client to the server
var client = new MongoClient(connectionString);
var server = client.GetServer();
// Connect to the MongoDB specified for the GDS on the Mongodb
var mongoDB = server.GetDatabase("test_database");
// create a collection called sample
var collection = mongoDB.GetCollection<sample>("sample");
sample a = new sample();
// Access the socket via which PLC has sent the data
a.Parameter = data;
collection.Insert(a);
答案 0 :(得分:1)
您可以在几个级别上声明所需的默认WriteConcern级别。
mongoClient.Settings.WriteConcern
database.Settings.WriteConcern
collection.Settings.WriteConcern
WriteConcern
对象的方法重载。当然,每个设置都可以被较低级别的不同设置覆盖。那么你选择哪个级别取决于你想做什么。