I have a problem with this query:
db.estudiantes.find({materias:{$gt:"3.0"}})
The intention of this is to find students who have failed at least one subject (the minimum passing grade is 3.0)
The data has this structure:
db.estudiantes.insert({
id:"1000",
nombre:"Diego Agreda",
edad:"15",
programa:"informatica",
materias:[{programacion:"5.0",leyes:"2.1",ingles:"4.1"}]
})
When launching the query
db.estudiantes.find({materias:{$gt:"3.0"}})
It doesn't give me any results. Why does that happen? How can I solve that?
I share with you the mongo operators, so you can analyze which option you are looking for with your query.
Other points to consider are:
Replicating your insert, with modifications that I consider you should make.
Now the query:
From what you tell me, from {name:1}, it is the visibility of the fields that I want to show, it is the mysql equivalent of:
Not every time we want to show all the fields of our tables, in this case collection.
Example:
Then:
Result:
Thanks to the contribution of annelyzzye and angel, I solved the scheme and the query, which turned out like this
and the query
If you modify your schema, in the matter property like this:
You can filter more easily in the following way:
In this way you get all the students who have subjects with grades lower than
3.0
, since according to what you mention it3.0
is passing.Explanation
This way of working is that a user can have an infinite number of subjects. A fix will allow us to have these subjects dynamically and filter the results more easily (in future queries).