查询

查询多条记录

语法格式:
db.collection.find(query, projection, options)
query为查询条件
projection为展示行规则
options为其他条件

使用

db.getCollection("books").find({}, {title: true, tag: true})
当titile和tag设置为true时则在查询结果中隐藏这些行
id为1时,其他字段必须是1,id为0时,其他字段可以是0
未使用前:
image
使用后:
image

查询单条记录

语法格式
db.collection.findOne(query, projection, options)

使用

db.getCollection("books").findOne({
})

条件查询

posted @ 2023-02-06 08:50  RainbowMagic  阅读(18)  评论(0)    收藏  举报