1

I have this document collection:

{
    _id: 3,
    version: "v1_8_R2"
}, 
{
    _id: 2,
    version: "v1_8"
}
{
    _id: 1,
    version: "v1_8_R3"
}

Using db.coll.find({version:"v1_8_R3"}) I get the id: 1 document, but id: 2 is compatible with the v1_8_R3 version and the id: 1 is outdated, and I don't want v1_8_R2 to be matched since it's incompatible with v1_8_R3

With regex I could solve that, but mongo doesn't allow to use it in fields unlike mysql

This works, but the other way around: db.coll.find(version: {$regex: "v1_8_R3", $options: "i"})

I would need something like this: db.coll.find({$regex: version, $options: "i"}: "v1_8_R3")

Then it would match v1_8, and wouldn't match v1_8_R2

6
  • Possible dupe of stackoverflow.com/questions/15966991/mongodb-reverse-regex Commented Jun 20, 2016 at 13:16
  • @JohnnyHK it has the regex inside the document. I don't Commented Jun 20, 2016 at 13:18
  • I thought you were looking to use the docs' version as a regex? Commented Jun 20, 2016 at 13:20
  • Let me test something, that gave me an idea Commented Jun 20, 2016 at 13:21
  • I do not understand what the goal is. If you want to match v1_8 and v1_8_R3, you may use a "^v1_8(?:_R3)?$" regex Commented Jun 20, 2016 at 13:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.