[英]Is it possible to use function in MongoDB $where clause?
我需要找出是否可以在$ where子句字符串中使用函数,如下所示:
db.myCollection.find( "this.name == 'xyz' || function() {return 1>0;} || this.name == 'abc'" );
提前致谢。
我不太确定您要执行的操作,但是将所有检查都放在$where
值的单个函数$where
:
db.myCollection.find({$where: function() {
return this.name == 'xyz' || 1>0 || this.name == 'abc';
}});
可以在JS的函数中使用嵌套函数,但是有一些注意事项,因为此问题将告诉您: JavaScript嵌套函数
但是,正如@JohnnyHK所说,如果有的话,这并不是在$where
上做的好方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.