简体   繁体   中英

Is there a “regex” operator in MongoDB? (not “$regex”)

I'm in a discussion with one of Yii2's developers about a regex issue I believe I found. The developer insists that the framework is passing all unit tests, but every time I try to run a query with a regex in it, I see this being ran in my MongoDB:

find({
    "ns":"todevise.category",
    "limit":0,
    "batchSize":0,
    "skip":0,
    "flags":0,
    "query":{
        "path":{
            "regex":"^/30000", // <---- issue?
            "flags":""
        }
    },
    "fields":{
        "short_id":true,
        "path":true
    },
    "started_iterating":false
})

Which I believe is not a valid MongoDB query as I can't find any documentation about regex operator. (Not to be confused with the $regex operator, anyways).

So, my question is: Is that query a valid MongoDB query? And if "yes", what is the difference between regex and $regex operators?

I belive that

{
  "regex":"^/30000", // <---- issue?
  "flags":"
}

is json object and both regex and $regex are keys of hash. But $regex is resreved keyword and recognized as operator that used to build query with condition. regex key in this case just ignored I guess.

$query->andFilterWhere([
      'path' => ['$regex'=> "^/30000"],
    ]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM