Bird
0
0

What will this Motor query return?

medium📝 query result Q5 of 15
FastAPI - Database Integration
What will this Motor query return?
cursor = db.users.find({"age": {"$gt": 30}})
users = await cursor.to_list(length=5)
AA single user older than 30
BA list of up to 5 users older than 30
CAn error because to_list is not async
DAll users regardless of age
Step-by-Step Solution
Solution:
  1. Step 1: Understand find and to_list

    find returns a cursor; to_list asynchronously converts it to a list with max length.
  2. Step 2: Analyze query filter and length

    Filter selects users with age > 30; to_list limits to 5 results.
  3. Final Answer:

    A list of up to 5 users older than 30 -> Option B
  4. Quick Check:

    find + to_list = list of filtered docs [OK]
Quick Trick: to_list converts cursor to list asynchronously [OK]
Common Mistakes:
MISTAKES
  • Expecting a single document from find
  • Thinking to_list is synchronous
  • Ignoring the filter condition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FastAPI Quizzes