Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB C# Query for 'Like' on string

i am using official mongodb c# driver. i want to query mongodb simliar to SQL Like something like db.users.find({name:/Joe/} in c# driver

like image 926
gsagrawal Avatar asked Dec 05 '11 07:12

gsagrawal


People also ask

What is MongoDB 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.

Is MongoDB a C++?

Welcome to the documentation site for the official MongoDB C++ driver. You can add the driver to your application to work with MongoDB using the C++11 or later standard.

Can you use MongoDB with C#?

By developing with C# and MongoDB together one opens up a world of possibilities. Console, window, and web applications are all possible. As are cross-platform mobile applications using the Xamarin framework.


1 Answers

c# query will looks like:

Query.Matches("name", BsonRegularExpression.Create(new Regex("Joe"))); 

Update:

As per @RoberStam suggestion, there is more simple way to do this:

Query.Matches("name", "Joe")  
like image 73
Andrew Orsich Avatar answered Sep 20 '22 13:09

Andrew Orsich