Question: Select All Documents in a Collection Selects from the inventory collection db . inventory.find ( { } ) In SQL: SELECT * FROM inventory To

Select All Documents in a Collection
Selects from the inventory collection db. inventory.find({})
In SQL: SELECT * FROM inventory
To specify equality conditions, use : expressions
Selects from the inventory collection all documents where the status equals "D". db.inventory.find({ status: "D"})
In SQL: SELECT * FROM inventory WHERE status ="D"
Selects from the inventory collection all documents where the status equals either "A" or "D": db.inventory.find({ status: { $in: ["A","D"]}})
In SQL: SELECT * FROM inventory WHERE status in ("A","D")
Specify AND, OR Conditions
All documents in the inventory collection where the status equals "A" and qty is 45: db.inventory.find({ status: "A", qty: 45})
In SQL: SELECT * FROM inventory WHERE status ="A" AND qty =45
All documents in the inventory collection where the status equals "A" or qty is 45: db.inventory.find({ $or: [{ status: "A"},{ qty: 45}]}) In SQL: SELECT * FROM inventory WHERE status ="A" OR qty =45
Use the limit () function to specify the maximum desired number of results. db.inventory.find().limit(2)
SELECT top(2)* FROM inventory

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!