Lab-MongoDB Query
Lab-MongoDB Query
2. Use the following command to delete all the documents in the inventory collection
db.inventory.deleteMany( {} )
4. Ascending/Descending sort
db.inventory.find( {} ).sort( { qty:1, item: -1 } ) What does this do?
c. Match an array
db.inventory.find( { tags: ["red", "blank"] } )
db.inventory.find( { tags: ["blank", "red"] } )
How about the following two? What does it mean by using the $all operator?
db.inventory.find( { tags: { $all: ["red", "blank"] } } )
db.inventory.find( { tags: { $all: ["blank", "red"] } } )
and
c. A projection can explicitly include several fields by setting the <field> to 1 in the
projection document (_id will be displayed by default)
db.inventory.find( { status: "A" }, { item: 1, status: 1 } )
A question for you. How to list only the item field of all documents?
db.inventory.find( { item: 1 } ) Does it work?
References
https://docs.mongodb.com/manual/
The course materials are only for the use of students enrolled in the course CSIS 3300 at Douglas
College. Sharing this material to a third-party website can lead to a violation of Copyright law.