在 , 的文档中,我MongoClient
看到据说它们是线程安全的。MongoServer
MongoDatabase
MongoCollection<T>
问题:这是否意味着我可以(例如)在一个类中拥有它们的静态字段并从任何Task
/访问它们Thread
?
像:
public static MongoClient Client = new MongoClient(Properties.Settings.Default.MongoConnStr);
public static MongoServer Server = Client.GetServer();
public static MongoDatabase DraftDB = Server.GetDatabase("draftdb");
public static MongoCollection<MyDoc> Docs = Program.DraftDB.GetCollection<Location>("mydocs");
特别是关于MongoCollection<T>
; 我想确保类似的东西var cursor = Docs.Find(query).SetLimit(50);
不会在MongoCollection<T>
(准确地说是静态)上执行突变。