MongoDB 有一个 $exists 运算符来检查文档中是否存在键。它与true
和一起使用false
。
Postgres 也可以存储 JSON 数据。以下 Mongodb 查询的 Postgres 等效项是什么?
db.myDocs.find_one({'myKey': { '$exists': False }})
MongoDB 有一个 $exists 运算符来检查文档中是否存在键。它与true
和一起使用false
。
Postgres 也可以存储 JSON 数据。以下 Mongodb 查询的 Postgres 等效项是什么?
db.myDocs.find_one({'myKey': { '$exists': False }})
如果要检查顶级字段,可以添加一个where
子句:
select * from myDocs
where column_name is null
limit 1;
如果要检查 json 字段的子字段,可以使用 jsonb?
运算符:
select * from myDocs
where column_name::jsonb ? 'myKey' is false -- or
-- where column_name::jsonb ? 'myKey' = false
limit 1;
jsonb?文本 → 布尔值
文本字符串是否作为 JSON 值中的顶级键或数组元素存在?