ใช้ $lt (Less Than) ใน find()
อ็อปเรเตอร์ $lt ใช้เปรียบเทียบค่าน้อยกว่า ในคำสั่ง find()
สร้างข้อมูลตัวอย่าง
> db.demo728.insertOne({Price:75});
> db.demo728.insertOne({Price:59});
> db.demo728.insertOne({Price:79});
> db.demo728.insertOne({Price:89});
แสดงข้อมูลทั้งหมด
> db.demo728.find();
ผลลัพธ์:
{ "_id" : ObjectId("5eab413c43417811278f589b"), "Price" : 75 }
{ "_id" : ObjectId("5eab414043417811278f589c"), "Price" : 59 }
{ "_id" : ObjectId("5eab414543417811278f589d"), "Price" : 79 }
{ "_id" : ObjectId("5eab414843417811278f589e"), "Price" : 89 }
คิวรีค้นหาราคาน้อยกว่า 80
> db.demo728.find({Price:{$lt:80}});
ผลลัพธ์
{ "_id" : ObjectId("5eab413c43417811278f589b"), "Price" : 75 }
{ "_id" : ObjectId("5eab414043417811278f589c"), "Price" : 59 }
{ "_id" : ObjectId("5eab414543417811278f589d"), "Price" : 79 }