mongodb - is filter is replaceable of query in mongo queries using c#? -


i'm new mongo in c#

i found tow ways find documents based on search critiria:

the first using filter:

var collection = _database.getcollection<bsondocument>("restaurants"); var filter = builders<bsondocument>.filter.eq("address.zipcode", "10075"); var result = await collection.find(filter).tolistasync(); 

the second using query:

mongocollection<bsondocument> books; var query = query.eq("author", "kurt vonnegut"); foreach (bsondocument book in books.find(query)) {     // book } 

what's best way find documents based mongodb recommendation?

as far know query builders (like second example using query.eq) belong old versions of c# drivers (1.x) (see query class). suggest see builder section in link confirm query builders old way consult data.

after release of 2.0 version of .net driver, lot of changes made, including way of consult data (you can read more in link). if using last c# driver version should use first approach.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -