Mongo DB :- Specify OR Conditions

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

Using the $or operator, you can specify a compound query that joins each clause with a logical OR conjunction so that the query selects the documents in the collection that match at least one condition.


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


Thank You !!!

Mongo DB :- Specify OR Conditions Mongo DB :- Specify OR Conditions Reviewed by Pubudu Dewagama on 5:37:00 PM Rating: 5

1 comment:

  1. If you're looking to lose fat then you certainly have to start using this brand new custom keto meal plan.

    To create this keto diet service, certified nutritionists, fitness trainers, and professional cooks have joined together to produce keto meal plans that are powerful, convenient, economically-efficient, and delicious.

    Since their first launch in 2019, 100's of people have already completely transformed their body and well-being with the benefits a great keto meal plan can give.

    Speaking of benefits: in this link, you'll discover eight scientifically-tested ones provided by the keto meal plan.

    ReplyDelete