Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 :

enter image description here

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 ?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
251 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...