I want to run a mongo query that only returns documents who's version field is bigger than '1.18.10'.
Related to: Regular expression for version number bigger than 1.18.10
I want to run a mongo query that only returns documents who's version field is bigger than '1.18.10'.
Related to: Regular expression for version number bigger than 1.18.10
To do a complex match like this, you'll need to use either the $regex or the $where operator: https://docs.mongodb.org/manual/reference/operator/query/#evaluation.
The regex to use with $regex would be something like this:
^(([2-9]|[0-9]{2,}).*|1\.(([0-9]{3,}|[2-9][0-9]|19).*|18\.([0-9]{3,}|[2-9][0-9]|1[1-9])))
The core logic is this part:
[2-9]|[0-9]{2,}|(1\.<check_next_part_here>)
which is repeated a few times throughout but slightly tweaked. This matches anything bigger than 1:
[2-9] (digits 2 to 9)[0-9]{2,} (two ore more digits: 10 onwards)Or 1 and then moves on to check the next part:
1\. (matches 1.)