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
<
It works for me
public class TestProductContext
{
MongoClient _client;
IMongoDatabase _db;
public TestProductContext()
{
_client = new MongoClient("mongodb://localhost:27017");
_db = _client.GetDatabase("EmployeeDB");
}
public IMongoCollection Products => _db.GetCollection("Products");
}
public class DataAccess
{
private TestProductContext _testProductContext;
public DataAccess(TestProductContext testProductContext)
{
_testProductContext = testProductContext;
}
public List GetProducts()
{
List pto = new List();
var cursor = _testProductContext.Products.Find(new BsonDocument()).ToCursor();
foreach (var document in cursor.ToEnumerable())
{
pto.Add(document);
}
}
}