Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex in MongoC

How can I do this query in mongoC with bcon_new?

 db.users.find({"name": /.*m.*/})
like image 397
faruk Avatar asked Jul 04 '15 01:07

faruk


People also ask

How regex works in MongoDB?

MongoDB provides the functionality to search a pattern in a string during a query by writing a regular expression. A regular expression is a generalized way to match patterns with sequences of characters. MongoDB uses Perl compatible regular expressions(PCRE) version 8.42 along with UTF-8 support.

How do I match a string in MongoDB?

Using $regex operator for Pattern matching The regex operator in MongoDB is used to search for specific strings in the collection.


1 Answers

After few try and error i finally found the answer based on libbson analogy

bson_t *query;

query = BCON_NEW ("name", BCON_REGEX("m","i") );
like image 62
faruk Avatar answered Sep 21 '22 07:09

faruk