0

Are either of these methods more optimized for querying using Mongo Db Driver for C# than the other?:

var 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);

Or

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);

Are there other recomendations to make this query better?

user1408767
  • 677
  • 1
  • 8
  • 30

1 Answers1

0

The first one will pull back every document and filter it client side where the 2nd will filter the documents server side and only pull back the ones that match. Use the 2nd one.

Craig Wilson
  • 12,174
  • 3
  • 41
  • 45