I'm trying to retrieve a single property from all the documents in a collection. And a want a way to filter the result for a period while setting a limit and getting distinct values.
This is the way my documents look in the collection:
{
_id: [ObjectId],
number: [string],
timestamp: [Datetime]
}
Im using the 2.7 version of the driver.
So i want to retrive the number field distinct for documents in a specific period of the timestamp property. And while the _id property is bigger then a specific one...
The queries i tried so far are:
var filter = Builders<Entity>.Filter.And(
Builders<Entity>.Filter.Gte(entity => entity.timestamp, startDate),
Builders<Entity>.Filter.Lte(entity => entity.timestamp, endDate),
Builders<Entity>.Filter.Gte(entity => entity.Id, objectId));
var query = collection
.DistinctAsync(item => item.number, filter);
No way to set a limit?
var filter = Builders<Entity>.Filter.And(
Builders<Entity>.Filter.Gte(entity => entity.timestamp, startDate),
Builders<Entity>.Filter.Lte(entity => entity.timestamp, endDate),
Builders<Entity>.Filter.Gte(entity => entity.Id, lastObjectId));
var query = collection
.Find(filter)
.Sort(Builders<Entity>.Sort.Ascending(entity => entity.number))
.Project(entity => new { entity.number})
.Limit(100);
No way to get distinct values?
Because of the size of the collection i do not want to do any of these operation on the client.
Do anybody have a solution? Thanks in advance!