Thanks for raising this. Serverless instances run on the latest MongoDB release of MongoDB (Version 5.3 as of the time of this message). As noted in the version 4.4 and 5.0 $regex documentation:
The $regex operator does not support the global search modifier g .
I did some testing with an Atlas cluster with the MongoDB version set to `Latest Release (auto-upgrades) which was version 5.3:
The error is returned when the g option is passed through.
Starting in MongoDB 5.1, invalid $regex options options are no longer ignored as per the noted changes. I presume the MongoDB cluster which did not return the error is at MongoDB version 5.0 or lower however please correct me if I am wrong here.
It was silently ignored in version 4.4 and 5.0 which is why no error is returned. As noted in my previous comment, starting in MongoDB Version 5.1, invalid $regex options are no longer ignored which resulted in the error you received when running the aggregation example you provided with the /g flag against a Serverless instance (which would have been MongoDB version 5.3 judging by the time of this post but correct me if i’m wrong here).