在mongodb中调用存储的函数 [英] Call stored function in mongodb

查看:37
本文介绍了在mongodb中调用存储的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调用mongdb中的存储函数遇到了一些困难. 我是mongo的新手.

I'm getting some difficulties to call a stored function within mongdb. I'm a little bit newbie with mongo.

:我的函数存储在mongodb中

: my function stored in mongodb

function() {
    var cndTime = new Date().getTime() - (3600*1000*24*2); // condition
     db.urls.find(needParse: false).forEach(function(item){
        if(item.date < cndTime)  // check
            db.urls.update({_id: item._id}, {$set: { needParse: true }}); // update field
     });
}

我要问的是如何使用reactmongo或本机API调用此函数.

All I'm asking is how to invoke this function using reactivemongo or native API.

推荐答案

在mongo shell中考虑以下示例,该示例首先将名为echoFunction的函数保存到system.js集合,然后使用db.eval()调用该函数:

Consider the following example from the mongo shell that first saves a function named echoFunction to the system.js collection and calls the function using db.eval():

db.system.js.save({
    _id: "echoFunction",
    value: function (x) {
        return 'echo: ' + x;
    }
})

db.eval("echoFunction('test')") // -> "echo: test"

echoFunction(...)eval/$where/mapReduce等中可用.更多信息在

echoFunction(...) is available in eval/$where/mapReduce etc. more information is available at http://docs.mongodb.org/manual/tutorial/store-javascript-function-on-server

这篇关于在mongodb中调用存储的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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