Javascript MongoDb-使用db.system.js中存储的函数时,$where的性能更高吗?
MongoDb建议“通常,只有在无法使用其他运算符表达查询时,才应使用$where”,因为性能原因。但是,我们似乎可以使用特殊的表Javascript MongoDb-使用db.system.js中存储的函数时,$where的性能更高吗?,javascript,node.js,performance,mongodb,Javascript,Node.js,Performance,Mongodb,MongoDb建议“通常,只有在无法使用其他运算符表达查询时,才应使用$where”,因为性能原因。但是,我们似乎可以使用特殊的表system.js在服务器端存储Javascript函数 因此,与其这样做,不如: db.myCollection.find( { $where: function() { return this.credits == this.debits; } } ); 改为这样做: db.system.js.save({ _id : 'queryFunction` , val
system.js
在服务器端存储Javascript函数
因此,与其这样做,不如:
db.myCollection.find( { $where: function() { return this.credits == this.debits; } } );
改为这样做:
db.system.js.save({ _id : 'queryFunction` , value : function() { return this.credits == this.debits; } });
...
db.myCollection.find( { $where: 'queryFunction' ); //not sure about syntax
第二种变体是否会获得任何性能优势;如果是这样,它们是否重要
参考资料:
- 这没用
在任何情况下,该函数都将作为字符串加载,并在MongodbsJavaScript引擎为每个单个文档执行之前编译到javascript函数。无论您是通过网络还是通过对
system.js
的查询来加载它,都不会有太大的区别,即使是这样,在大多数情况下,运行时的大部分时间都是函数的执行。尝试和测量很简单,不是吗?谢谢,这正是我想要的。