I want to query my MongoDB collection without any filter with MongoDB .NET Driver 2.0 but I didn't find a way. I have the following workaround but it looks weird :D
var filter = Builders<FooBar>.Filter.Exists(x => x.Id);
var fooBars = await _fooBarCollection.Find(filter)
.Skip(0)
.Limit(100)
.ToListAsync();
Is there a way to issue queries without a filter in MongoDB .NET Driver 2.0?
You can't use Find
without a filter.
You can however use a filter that passes everything:
var findFluent = await _fooBarCollection.Find(_ => true);
Or you can use an empty document which is equivalent:
var findFluent = await _fooBarCollection.Find(new BsonDocument());
They have also added an empty filter but it will only be available in newer versions of the driver:
var findFluent = await _fooBarCollection.Find(Builders<FooBar>.Filter.Empty);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With