1
有了以下条目:MongoDB的选择,所有子域具有特定价值
{id : "a1", b: {"123":1, "345":2}}
{id : "a2", b: {"123":null, "345":2, "567":3}}
{id : "a3", b: {"123":null, "345":null, "567":null}}
我如何可以查询所有,有“B”是空的所有子域?
有了以下条目:MongoDB的选择,所有子域具有特定价值
{id : "a1", b: {"123":1, "345":2}}
{id : "a2", b: {"123":null, "345":2, "567":3}}
{id : "a3", b: {"123":null, "345":null, "567":null}}
我如何可以查询所有,有“B”是空的所有子域?
我认为你在寻找这样的事情
db.col.find({$or: [
{$and: [ {"b.123": null}, {"b.123":{$exists : true}} ]},
{$and: [ {"b.345": null}, {"b.345":{$exists : true}} ]},
{$and: [ {"b.567": null}, {"b.567":{$exists : true}} ]}
]})