FindAll in MongoDB .NET Driver 2.0

前端 未结 3 697
既然无缘
既然无缘 2021-02-19 07:50

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

<         


        
3条回答
  •  旧时难觅i
    2021-02-19 08:31

    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.Filter.Empty);
    

提交回复
热议问题