For a building security system I want to get the last swiped card time for a particular student based on their id serial number. I am using this code
var _collection = database.GetCollection<BsonDocument>("entrycard_swipetimes");
var filter = Builders<BsonDocument>.Filter.Eq("studentid", "stu-1234") & Builders<BsonDocument>.Filter.Eq("Carddetails.LastSwipeTimestamp", "2021-11-25T10:50:00.5230694Z");
var doc = _collection.Find(filter).FirstOrDefault();
This is a snippet of the json document
{
"studentid"; "stu-1234",
"Carddetails":
{
"LastSwipeTimestamp": "2021-11-25T10:50:00.5230694Z"
}
}
The code above works and I get a record, but I need to know the exact time string in advance. How can get only the last time a particular student swiped their card? How do I get the last timestamp of all the students in the system and have it paged by say 20 students at a time for the last 30 days?