1
這是一段代碼段,我將PLC數據插入到MongoDB中,但我不確定WriteConcern必須在哪裏實現?必須在哪裏寫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);
@Philipp嗨, 如果我想WriteConcern在集合級別,將它像: 'collection.Insert(一,新MongoInsertOptions { WriteConcern = WriteConcern.WMajority } ); ' 這個? – Arjun
@Arjun或者只是做'collection.Insert(a,WriteConcern.WMajority)'但是這只是針對這一個查詢,而不是針對同一個集合的未來查詢。 – Philipp
好的,這很有道理。所以,我想要做的是在集合級別有一個WriteConcern,只要數據插入到集合中,MongoDB就會發送一個確認消息。你上面提到的陳述怎麼可以改變成這樣? – Arjun