Loopbackjs Loopback4和MongoDB查询字段为空或未定义的文档

Loopbackjs Loopback4和MongoDB查询字段为空或未定义的文档,loopbackjs,loopback4,Loopbackjs,Loopback4,如何查询字段为空或未定义的文档 e、 g 我已经试过这个代码,但没有用。返回0个匹配项 const whereBuilder=new whereBuilder(); 常量where:where=whereBuilder .eq('updatedAt',null) //.eq('updatedAt',false) .build(); myRepository.findOne({ where:where, }); 使用运算符匹配未定义的值,请参阅 //匹配`未定义` findOne({updat

如何查询字段为空或未定义的文档

e、 g

我已经试过这个代码,但没有用。返回0个匹配项

const whereBuilder=new whereBuilder();
常量where:where=whereBuilder
.eq('updatedAt',null)
//.eq('updatedAt',false)
.build();
myRepository.findOne({
where:where,
});
使用运算符匹配未定义的
值,请参阅

//匹配`未定义`
findOne({updatedAt:{'$type':6}});
//匹配'null`
findOne({updatedAt:null});

在LB4中

//匹配`未定义`
返回等待this.myRepository.find(
{
其中:{
//!!!!“$”将自动添加到此处。(解释如下)
updatedAt:{“类型”:6}
},
}
);
//匹配'null`
返回等待this.myRepository.find(
{
其中:{
updatedAt:null
},
}
);

为什么
{'type':6}
将转换为
{'type':6}
/node\u模块/环回连接器mongodb/lib/mongodb.js
第918行:

您的
其中
将在此函数中重构

MongoDB.prototype.buildWhere=函数(modelName、where、options){
...

在第1011行,
{'type':6}
将转换为
{'type':6}

。。。
}否则{
查询[k]={};
查询[k]['$'+spec]=cond;
}
...

顺便说一下,在第1016行中,您可以看到
null
将转换为
{$type:10}

。。。
如果(cond==null){
// http://docs.mongodb.org/manual/reference/operator/query/type/
//空:10
查询[k]={$type:10};
}否则{
...

在MongoDB Shell中 使用运算符匹配未定义的
值,请参阅

//匹配`未定义`
findOne({updatedAt:{'$type':6}});
//匹配'null`
findOne({updatedAt:null});

在LB4中

//匹配`未定义`
返回等待this.myRepository.find(
{
其中:{
//!!!!“$”将自动添加到此处。(解释如下)
updatedAt:{“类型”:6}
},
}
);
//匹配'null`
返回等待this.myRepository.find(
{
其中:{
updatedAt:null
},
}
);

为什么
{'type':6}
将转换为
{'type':6}
/node\u模块/环回连接器mongodb/lib/mongodb.js
第918行:

您的
其中
将在此函数中重构

MongoDB.prototype.buildWhere=函数(modelName、where、options){
...

在第1011行,
{'type':6}
将转换为
{'type':6}

。。。
}否则{
查询[k]={};
查询[k]['$'+spec]=cond;
}
...

顺便说一下,在第1016行中,您可以看到
null
将转换为
{$type:10}

。。。
如果(cond==null){
// http://docs.mongodb.org/manual/reference/operator/query/type/
//空:10
查询[k]={$type:10};
}否则{
...

感谢您的快速回复。该字段声明为:
@property({type:'date',})updatedAt?:string;
使用上述代码时,我收到一个类型错误。
{where:{updatedAt:{'type':6}}}
{where:{updatedAt:{'type':6}作为任何对象}
感谢您的快速回复。该字段声明为:
@property({type:'date',})updatedAt?:string;
使用上述代码时,我收到一个类型错误。
{where:{updatedAt:{'type':6}}}
{where:{updatedAt:{'type':6}作为任何对象}
{id:1, updatedAt: null}
{id:2}