หากต้องการตรวจสอบระเบียนที่มีราคาน้อยกว่าค่าที่ระบุ ให้ใช้ $lt ให้เราสร้างคอลเลกชันที่มีเอกสาร -
> db.demo728.insertOne({Price:75});
{
"acknowledged" : true,
"insertedId" : ObjectId("5eab413c43417811278f589b")
}
> db.demo728.insertOne({Price:59});
{
"acknowledged" : true,
"insertedId" : ObjectId("5eab414043417811278f589c")
}
> db.demo728.insertOne({Price:79});
{
"acknowledged" : true,
"insertedId" : ObjectId("5eab414543417811278f589d")
}
> db.demo728.insertOne({Price:89});
{
"acknowledged" : true,
"insertedId" : ObjectId("5eab414843417811278f589e")
} แสดงเอกสารทั้งหมดจากคอลเล็กชันโดยใช้วิธี find() -
> db.demo728.find();
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
{ "_id" : ObjectId("5eab413c43417811278f589b"), "Price" : 75 }
{ "_id" : ObjectId("5eab414043417811278f589c"), "Price" : 59 }
{ "_id" : ObjectId("5eab414543417811278f589d"), "Price" : 79 }
{ "_id" : ObjectId("5eab414843417811278f589e"), "Price" : 89 } ต่อไปนี้เป็นแบบสอบถามเพื่อค้นหาบันทึกตามเงื่อนไข -
> db.demo728.find({Price:{$lt:80}}); สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
{ "_id" : ObjectId("5eab413c43417811278f589b"), "Price" : 75 }
{ "_id" : ObjectId("5eab414043417811278f589c"), "Price" : 59 }
{ "_id" : ObjectId("5eab414543417811278f589d"), "Price" : 79 }