Mongo DB:- Select Documents in a Collection

In this post I am going to explain how to select documents from Mongo DB collection . for this as a sample data you have to upload data into mongo db database.

db.inventory.insertMany([
   { item: "journal", qty: 25, size: { h: 14, w: 21, uom: "cm" }, status: "A" },
   { item: "notebook", qty: 50, size: { h: 8.5, w: 11, uom: "in" }, status: "A" },
   { item: "paper", qty: 100, size: { h: 8.5, w: 11, uom: "in" }, status: "D" },
   { item: "planner", qty: 75, size: { h: 22.85, w: 30, uom: "cm" }, status: "D" },
   { item: "postcard", qty: 45, size: { h: 10, w: 15.25, uom: "cm" }, status: "A" }
]);



To select all documents in the collection, pass an empty document as the query filter parameter to the find method. The query filter parameter determines the select criteria:

Then you can execute below query.
db.inventory.find({}) 
Above selection command is identical to "Select * from inventory" in the SQL

Mongo DB:- Select Documents in a Collection Mongo DB:- Select Documents in a Collection Reviewed by Pubudu Dewagama on 12:06:00 AM Rating: 5

No comments: