问题
I'm using C3 with mongo and I'm trying to query documents by dateCreated
property.
For example , if I extract the first record by :
var models = await c.FindAsync(a=>true);
var list = await models.ToListAsync();
list.First().Dump();
Then I see the result :
Please notice that the value is BsonString
, and that I have no entity behind it.
The problem is that now , I want to query the collection based on datetime :
So I did this :
var filter = Builders<BsonDocument>
.Filter
.And
(
Builders<BsonDocument>.Filter.Gte(x => x["dateCreated"].AsBsonDateTime , DateTime.Today.AddDays(-10000)) // old enough
);
var models = await c.FindAsync(filter);
var list = await models.ToListAsync();
list.First().Dump();
But I get : InvalidOperationException: Sequence contains no elements
Question:
How can I query the collection based on datetime knowing that the collection date is stored as BsonString ?
来源:https://stackoverflow.com/questions/65503195/cannot-use-mongos-filter-with-datetime-and-bsonstring