D
D
driver4582017-08-03 02:24:35
JavaScript
driver458, 2017-08-03 02:24:35

How to select documents from mongodb where value is in given range?

{ $gte: 6, $lte: 8 };
does not work, apparently because the values ​​are stored in the database as strings
in this case, it gives me documents that start with "6" or "7", for example: "6990", "61990", "7290"
What is better to do in such situation? Perhaps there is a function that will compose a regular expression? or what is faster

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Shashenkov, 2017-08-03
@teknik2008

And it doesn't roll?
Or would it be easier to write string to number

C
Coder321, 2017-08-05
@Coder321

According to the idea, it should not work, if I'm not mistaken, it should be something like: or
{$and:[{field:{$gte: 6}}, {field:{$lte: 8}}]}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question