97.5k views
0 votes
Question 14 (2 points) Assuming documents in a collection called employees have the following fields: - name: required - age: required - base_salary: required - bonus: optional Write a query to retrie

User Fizk
by
8.5k points

1 Answer

7 votes

Final answer:

To retrieve documents from the employees collection where the age is greater than 30 and the base_salary is less than 50000, you can use the following query:

Step-by-step explanation:

To retrieve documents from the employees collection where the age is greater than 30 and the base_salary is less than 50000, you can use the following query:

This query uses the find() method on the employees collection and specifies two conditions using the $gt and $lt operators. The $gt operator selects documents where the age field is greater than 30, and the $lt operator selects documents where the base_salary field is less than 50000. The query returns a cursor object, which can be iterated to access the matching documents.

db.employees.find({ age: { $gt: 30 }, base_salary: { $lt: 50000 } })db.employees.find({ age: { $gt: 30 }, base_salary: { $lt: 50000 } })

User Grasaved
by
8.0k points