如何访问MongoDB中只设置为null而不设置为undefined的数据(在某些字段中)?解决了罗盘上的一个错误

如何访问MongoDB中只设置为null而不设置为undefined的数据(在某些字段中)?解决了罗盘上的一个错误,mongodb,null,set,undefined,Mongodb,Null,Set,Undefined,如何访问MongoDB中某个字段中仅设置为null而未定义的数据 我尝试了$exists:true和$and,但没有成功 对此的适当查询是什么 已解决: Compass中的是was bug这段代码有效{$and:[{tripdurationr:{$exists:true}},{tripdurationr:null}}}但是Compass将不需要的字母r添加到键tripduration中,因此我的查询没有成功: 如果我理解你的问题是正确的: db.things.insert({a: null, b

如何访问MongoDB中某个字段中仅设置为null而未定义的数据

我尝试了$exists:true和$and,但没有成功

对此的适当查询是什么

已解决:
Compass中的是was bug这段代码有效{$and:[{tripdurationr:{$exists:true}},{tripdurationr:null}}}但是Compass将不需要的字母r添加到键tripduration中,因此我的查询没有成功:

如果我理解你的问题是正确的:

db.things.insert({a: null, b: 1});
db.things.insert({b: 2});
db.things.find({$and:[{a: null }, {a: {$exists: true}}]});
输出:

{ "_id" : ObjectId("5b0efa710d9b6861ee36052e"), "a" : null, "b" : 1 }
{ "_id" : ObjectId("5b0efe730d9b6861ee360531"), "a" : null, "b" : 1 }
{ "_id" : ObjectId("5b0efe7b0d9b6861ee360533"), "a" : undefined, "b" : 3 }
但要注意以下几点:

db.things1.insert({a: null, b: 1});
db.things1.insert({b: 2});
db.things1.insert({ a: undefined, b: 3 });
db.things1.find({$and:[{a: null }, {a: {$exists: true}}]});
输出:

{ "_id" : ObjectId("5b0efa710d9b6861ee36052e"), "a" : null, "b" : 1 }
{ "_id" : ObjectId("5b0efe730d9b6861ee360531"), "a" : null, "b" : 1 }
{ "_id" : ObjectId("5b0efe7b0d9b6861ee360533"), "a" : undefined, "b" : 3 }

第二部分要阅读的参考文本:并且可能

发布您的样本集…而对您不起作用的查询。{$and:[{$tripdurationr:{$exists:true}},{tripdurationr:null}}不起作用