[英]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.