Obtain users with points between 0-10, 11-20 ... MongoDB

1

I need to obtain from a database of mongo users whose points range from 0-10 , 11-20 , 21-30 ... so up to 100 points. The points field is of type string. The final idea is to get something similar to this:

0-10.
Usuario :554545    Puntos:1.
Usuario :111154    Puntos:7.
11-20.
Usuario :554545    Puntos:15.
Usuario :554545    Puntos:18.

Etc...

I need to do tests in Robo3T but the idea of the query will be to associate it with a batch (in java) that will consult the database and get the result in a file.

Thank you very much.

    
asked by AnnaPS 22.08.2018 в 13:55
source

1 answer

0

try this, so the rank queries are done ...

In this way you are looking for minors or equals:

                            inclue el cero y exclue el 11 = 0-10
db.nombreBD.find({ puntos: { $lt: 0, $gte: 11 }, type: "Usuario" })

db.nombreBD.find({ puntos: { $lt: 11, $gte: 21 }, type: "Usuario" })

In this way you are looking for minors only:

db.nombreBD.find({ puntos: { $lte: 10 } })

I leave you the link that can help you much more

    
answered by 22.08.2018 в 15:15