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}} ]}
]})