[英]Does MongoDB GetCollection method load the entire collection into RAM or a reference? C#
我有一個存儲庫類,可以處理MongoDB的所有數據庫功能,這是構造函數的實現:
public LocationRepository(string connectionString)
{
if (string.IsNullOrWhiteSpace(connectionString))
{
connectionString = "mongodb://localhost:27017";
}
_client = new MongoClient(connectionString);
_server = _client.GetServer();
_database = _server.GetDatabase("locDb");
_collection = _database.GetCollection<Location>("Location");
}
然后我做類似的事情:
_collection.Insert(locationObject)
在該類的其他方法中。
我想知道考慮到有限的內存是否明智? 如果沒有,是否存在一種建議的方法,可以直接將其持久保存到數據庫而不必加載集合。
GetCollection
不會加載集合,甚至Find()
都不會加載。 實際上,在從數據庫中實際加載任何內容之前,您必須開始迭代MongoCursor
,即使那樣,它也不會加載整個集合,而只會加載可配置大小的批處理。
例如,如果您想實際加載整個集合,則可以在MongoCursor
上調用ToList()
,但是當然這幾乎沒有道理。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.