[SERVER-54588] Query on system.profile() failing when certain regex is recorded Created: 17/Feb/21  Updated: 06/Dec/22  Resolved: 04/Mar/21

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 4.4.4
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Adamo Tonete (Inactive) Assignee: Backlog - Query Execution
Resolution: Won't Do Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to MONGOSH-623 Retrieving stored PCRE-style regex ca... Closed
is related to DRIVERS-82 Don't compile BSON regexes to native ... Closed
Assigned Teams:
Query Execution
Operating System: ALL
Steps To Reproduce:

 

1. Using Ruby but it also works on C# and likely other drivers.

2. File called repro.rb contains the following code:

require 'bundler/inline'
gemfile do
  source 'https://rubygems.org'
  gem 'mongo'
end
Mongo::Logger.logger.level = Logger::DEBUG
client = Mongo::Client.new('mongodb://127.0.0.1/test')
collection = client[:foo]
puts collection.find( { rubyprogramtestRegexWihtM: /(?-i)AA_/im } ).first

3. File called repro2.rb contains the following code:

require 'bundler/inline'
gemfile do
  source 'https://rubygems.org'
  gem 'mongo'
end
Mongo::Logger.logger.level = Logger::DEBUG
client = Mongo::Client.new('mongodb://127.0.0.1/test')
collection = client[:foo]
puts collection.find( { rubyprogramtestRegexWihtoutM: /(?-i)AA_/i } ).first

 

— Steps to reproduce —

#lauching mongodb*

mlaunch --single

#setting profiler to 2
mongo localhost/test --eval "db.setProfilingLevel(2)"

#executing first repro, please note we are specifyng /im here
ruby repro.rb

#attempt to read the system.profile()
mongo localhost/test --eval "db.system.profile.find()"

Expected error: Error: Error: SyntaxError: invalid regular expression flag s

#dumping the system.profile collection:
mongoexport -d test -c system.profile | grep rubyprogramtestRegexWihtM

#cleaning the system profile collection for a new test without /m*
mongo localhost/test --eval "db.setProfilingLevel(0); db.system.profile.drop();db.setProfilingLevel(2);"

#executing the second test without specifying /m*
ruby repro2.rb

#attempt to read the system.profile()
mongo localhost/test --eval "db.system.profile.find()"

expected error: Error: invalid regexp group

#dumping the system.profile collection:
mongoexport -d test -c system.profile | grep rubyprogramtestRegexWihtoutM

Sprint: Query Execution 2021-03-22
Participants:
Case:

 Description   

When running find command on system.profile if the recorded command contains specific regex the shell is returning an error.

 

Some error messages are:
1.  SyntaxError: invalid regular expression flag s
2. Error: invalid regexp group

Repro attached



 Comments   
Comment by Bernard Gorman [ 04/Mar/21 ]

I don't believe the server is doing anything wrong here, since it's correctly interpreting a BSONRegex argument that is sent to it - the only "problem" is that the BSONRegex encodes a native PCRE expression. Our docs page specifically mentions the (?-i) pattern as one which Javascript does not support, and which must therefore be supplied as a string using the $regex form, but the entire docs page is written from the perspective of a Javascript client.

In order for the server to address this, we would have to manually validate that an expression which PCRE successfully compiles nonetheless does not adhere to our documented rules about what can be expressed in /regex/ format and what must be expressed in $regex:"" format on the driver's side. I don't think that's sensible, given that those rules are not really restrictions, but rather explain how a Javascript client which cannot understand PCRE /patterns/ can nonetheless send PCRE patterns to the server.

Looks like the Drivers team already handled this issue long ago (DRIVERS-82) so I'll open a ticket for the same work to be done by the new shell.

Generated at Thu Feb 08 05:33:56 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.