A
A
AleDv2020-08-08 14:44:12
MongoDB
AleDv, 2020-08-08 14:44:12

Correct indication of the AND condition of a query in Mongo?

Hello. I'm trying Mongo and ran into a problem using the AND operator. For training, I use the dataset at the link .

I'm trying to find students by the condition:

students = db.find({"scores.score": {"$gt": 99.5}, "scores.type": "exam"})

And I get this result:
{'_id': 69,
 'name': 'Cody Strouth',
 'scores': [{'score': 4.784730508547719, 'type': 'exam'},
            {'score': 99.80348240553108, 'type': 'quiz'},
            {'score': 97.89665889862901, 'type': 'homework'}]}
{'_id': 178,
 'name': 'Whitley Fears',
 'scores': [{'score': 20.84454374176408, 'type': 'exam'},
            {'score': 57.14851257871499, 'type': 'quiz'},
            {'score': 99.77237745070993, 'type': 'homework'}]}


I want to find a document in which one of the objects in scores will satisfy both conditions.

The documentation has an example, one to one with my task (the last one). It works there, I don't. What am I missing?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
fostsinger, 2020-08-11
@fostsinger

you need to use the $in operator

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question