如何通过猫鼬调用db.eval()? [英] How to call db.eval() via mongoose?

查看:74
本文介绍了如何通过猫鼬调用db.eval()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MongoDB服务器中保存了一些功能. 是否有一些方法可以调用它们,例如本地调用db.eval().

I have some functions saved in MongoDB Server. Is there some methods to call them, like the native call db.eval().

可能是这样(我尝试过,不起作用):

May be like this (I Tried, not work):

mongoose.connection.db.eval("Foo('Arg1','Arg2')", function(err, retVal) {
    // the eval result
});

或者这(也不起作用):

or this (not work either):

mongoose.connection.db.eval("Foo", ['Arg1','Arg2'], function(err, retVal) {
    // the eval result
});

从未调用过callback函数. 而mongoose.connection.db.eval的返回值为undefine.

The callback function was never called. And the return of mongoose.connection.db.eval was undefine.

推荐答案

尝试一下:

mongoose.connection.db.eval('function(foo) {return foo;}', 'bar', {}, function(err, result) {
    console.log(result);
});

这篇关于如何通过猫鼬调用db.eval()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆