假設我在 mongodb 集合中有數千個檔案。每個隨機檔案都包含具有兩個屬性(ownerId、ownerRef)的物件 ownerData
{
"_id": {....},
"name": "abc",
"ownersData": { "ownerId":"1", "ownerRef":"qwer" }
}
使用某些檔案包含某些 ownerRef 值的資訊查詢所有檔案的最快方法應該是什么
uj5u.com熱心網友回復:
假設您有表示資料庫中資料的 C# 物件,您可以使用 linq 來實作這一點。
public IEnumerable<Document>? GetDocumentByOwnerRef(string ownerReference)
=> dbContext.Documents.Where(d =>
d.ownerData is not null && d.ownersData.ownerRef.Equals(ownerReference)
).ToList();
編輯:正如@SJFJ 在評論中正確指出的那樣;雖然這確實有效,但它會掃描您的整個收藏,使其成為一個非常漫長的程序。ownerRef在 mongodb的列上創建索引將節省性能和加載時間。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/381409.html
上一篇:找不到ISOWeek
