Reputation: 113
I am getting an error below
Command aggregate failed: Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting. Aborting operation. Pass allowDiskUse:true to opt in..
Below is my sample code that has a lot of sorting and has big data. How do I allowDiskUse to true based on my sample below?
var collection = _context.GetCollection<SampleCollection>();
var result = collection.AsQueryable();
result = result.OrderByDescending(x => x.Date)
.ThenByDescending(d => d.Status)
.ThenByDescending(r => r.Firstname)
.ThenByDescending(d => d.Lastname)
.ThenByDescending(d => d.Birthdate)
.ThenByDescending(d => d.Sex);
return result .ToList();
Upvotes: 0
Views: 314
Reputation: 4897
See below:
var client = new MongoClient();
var db = client.GetDatabase("db");
var collection = db.GetCollection<SampleCollection>("c");
var result = collection.AsQueryable<SampleCollection>(new AggregateOptions() { AllowDiskUse = true });
var res = result.OrderByDescending(x => x.Date)
.ThenByDescending(d => d.Status)
.ToList();
Upvotes: 0