2012-05-21 58 views
0

是以下任一方法,用於查詢使用蒙戈DB驅動爲C#比其他?:更優化對於使用Mongo Db Driver for C#查詢而不是其他方法,哪種方法更優化?

變種partsLogs = MvcApplication.MongoLoggingDatabase.GetCollection( 「PartDetailLog」) .FindAll()

  .Where(x => x.UserId == UserId) 
      .Select(x => new RecentActivityPartsLogDto { OemCode = x.Request.OemCode, OemPartCode = x.Request.OemPartCode, OemPartDescription = x.Request.OemPartDescription, TimeStamp = x.TimeStamp, UserId = x.UserId.ToString() }) 
      .OrderByDescending(x => x.TimeStamp) 
      .Skip(pageSize * (page - 1)) 
      .Take(pageSize); 

或者

var doc = new QueryDocument(); doc [「UserId」] = UserId;

VAR partsLogs = MvcApplication.MongoLoggingDatabase.GetCollection( 「PartDetailLog」)

.Find(doc)    
      .Select(x => new RecentActivityPartsLogDto { OemCode = x.Request.OemCode, OemPartCode = x.Request.OemPartCode, OemPartDescription = x.Request.OemPartDescription, TimeStamp = x.TimeStamp, UserId = x.UserId.ToString()}) 
      .OrderByDescending(x => x.TimeStamp) 
      .Skip(pageSize*(page - 1)) 
      .Take(pageSize); 

是否有其他recomendations使這個查詢更好嗎?

回答

0

第一個將退回每個文檔並將其過濾到客戶端,其中第二個將過濾文檔服務器端並僅將相匹配的文檔進行回退。使用第二個。