[CDRIVER-206] using mongo-c-driver can not use regular expressions containing forward slash (/) Created: 12/Apr/13  Updated: 12/Nov/13  Resolved: 12/Nov/13

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: 0.7
Fix Version/s: 0.90.0

Type: Bug Priority: Major - P3
Reporter: Joshua Stillerman Assignee: Christian Hergert
Resolution: Done Votes: 0
Labels: query
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Redhat linux



 Description   

I am trying to use the C-API for mongo DB. I want to find records with a name matching a regular expression containing slashes . If I run the mongo command line I get 40 results for the query:
db.test_006.find(

{'name':/^\/TEST::TOP:NEWSTAT\/_data_[0-9]*/}

)
which is correct. When I try to code this in C I can not get it to match.
using:
bson_append_regex( &query, "name","/TEST::TOP:NEWSTAT/" , "" )
I find all the records and more.
All combinations of
/ or even [/] or \\/ do not find any records. I also tried
x2F.



 Comments   
Comment by Christian Hergert [ 12/Nov/13 ]

Hi,

You do not need to include the forward-slash when building a regex.

I've added a test for this using the new C driver here[1] which you can use as an example.

[1] https://github.com/chergert/libmongoc/blob/211e987ba0c2771199a1c01fc486a57966daa509/tests/test-mongoc-collection.c#L55

Generated at Wed Feb 07 21:08:46 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.