我正在使用猫鼬在节点中操作mongodb。现在我必须从Post表中查询条目,其中的标签不包含任何标签,例如inc:___,inc:gdc,exc:abc,exc:57uyht7,所有其他标签都可以使用(test,card,check)。
PostModel.Post.find({
$where:this.activeFlag==true && (this.tags!= null && this.tags != /^inc:/ && this.tags !=/^exc:/)
}), function(err, stack) {
if (!err) {
logger.debug('Posts found successfully.');
} else {
logger.error('Problem in finding posts, error :' + err);
}
});
但这是行不通的。我的查询也使用inc:dbgh来获取条目。谁能帮我?提前致谢。
根据Mongo docs,您应该将字符串或javascript函数$where
传递给,然后传递javascript表达式,该表达式将在适当位置进行评估。
此外,您的查询可以简化为
PostModel.Post.find({
activeFlag: true,
tags: {
$exists: true,
$not: /^(inc:|ecx:)/
}
}, function(err, stack) {
if (!err) {
logger.debug('Posts found successfully.');
} else {
logger.error('Problem in finding posts, error :' + err);
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句