查找价格低于特定值
要检查价格低于特定值记录,请使用 $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 }
广告