Mongo DB:- Conditions Using Query Operators ( in )

In this post I am going to explain how to Specify Equality Condition 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" }
]);





Then you can execute below query.
db.inventory.find( { status: { $in: [ "A", "D" ] } } ) 
Above selection command is identical to
"SELECT * FROM inventory WHERE status in ('A', 'D')
in the SQL


Thank You !!!

Mongo DB:- Conditions Using Query Operators ( in ) Mongo DB:- Conditions Using Query Operators ( in ) Reviewed by Pubudu Dewagama on 5:47:00 PM Rating: 5

No comments: