MongoDB 查询文档
find(cond) 查询文档,find({}) 返回全部;pretty() 格式化输出,条件以 JSON 形式表达。
Key PointsMongoDB,find,查询,pretty
讲解
find(cond) 查询文档,find({}) 返回全部;pretty() 格式化输出,条件以 JSON 形式表达。
示例
JavaScript
db.site.find({ title: "菜鸟教程" })
db.site.find({ alexa: { $gt: 10 } }).pretty()
// AND:多个键值并列;OR:$or
db.site.find({ title: "Google", alexa: 1 })
db.site.find({ $or: [{ title: "Google" }, { alexa: { $gt: 100 } }] })Output
{
_id: ObjectId("..."),
title: "菜鸟教程",
url: "https://www.runoob.com",
alexa: 4689
}讲解
find(cond) 查询文档,find({}) 返回全部;pretty() 格式化输出,条件以 JSON 形式表达。
示例
JavaScript
db.site.find({ title: "菜鸟教程" })
db.site.find({ alexa: { $gt: 10 } }).pretty()
// AND:多个键值并列;OR:$or
db.site.find({ title: "Google", alexa: 1 })
db.site.find({ $or: [{ title: "Google" }, { alexa: { $gt: 100 } }] })Output
{
_id: ObjectId("..."),
title: "菜鸟教程",
url: "https://www.runoob.com",
alexa: 4689
}