Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongo C# driver - Contains Filter

I am using the latest version of Mongo C# driver which uses a lot of Async and builder pattern. Which is nice. I am trying to convert SQL where clauses into Mongo FilterDefinition object.

Any idea how to handle "contains"?
like:

where x contains 'ABC'
like image 782
Mr767267 Avatar asked Aug 21 '15 10:08

Mr767267


People also ask

What is MongoDB C tutorial?

C# tutorial is a comprehensive tutorial on C# language. MongoDB is a NoSQL cross-platform document-oriented database. It is one of the most popular databases available. MongoDB is developed by MongoDB Inc. and is published as free and open-source software.

What is libmongoc in MongoDB?

The MongoDB C Driver, also known as “libmongoc”, is a library for using MongoDB from C applications, and for writing MongoDB drivers in higher-level languages. It depends on libbson to generate and parse BSON documents, the native data format of MongoDB.

What is Mongo-C-driver?

The MongoDB C Driver, also known as “libmongoc”, is a library for using MongoDB from C applications, and for writing MongoDB drivers in higher-level languages. It depends on libbson to generate and parse BSON documents, the native data format of MongoDB. Latest release: mongo-c-driver-1.20.1.tar.gz

What should I look for in a C++ driver for MongoDB?

If you’re just starting out, take a look at these pages first: Stability indicates whether this driver is recommended for production use. Currently, no drivers guarantee API or ABI stability. Compatibility of each C++ driver version with each MongoDB server is documented in the MongoDB manual.


1 Answers

I was able to get this working using Filter.AnyIn like so

var filter = Builders<BsonDocument>.Filter.AnyIn("x", new List<string> { "ABC" });

This works if you're looking for multiple values too, just add them to the list.

like image 99
reggaeguitar Avatar answered Sep 18 '22 16:09

reggaeguitar