mongodb:如何在 mongodb shell 上调试 map/reduce

发布于 2024-12-06 01:23:56 字数 482 浏览 1 评论 0原文

我是 MongoDB 新手,我正在使用 map/reduce。 有人可以告诉我如何在使用 Map/Reduce 时进行调试吗?我使用了“print()”函数,但在 MongoDB shell 上,没有打印任何内容。以下是我的reduce函数:

    var reduce = function(key, values){
        var result = {count: 0, host: ""};

        for(var i in values){
        result.count++;
        result.host = values[i].host;
        print(key+" : "+values[i]);
        }
        return result;
    }

当我在shell上编写上述函数并在完成后按Enter键时,shell上没有打印任何内容。我还应该做些什么来调试吗?

谢谢

I am new to MongoDB, I am using map/reduce.
Can somebody tell me how to debug while using map/reduce? I used "print()" function but on MongoDB shell, nothing is printed. Following is my reduce function:

    var reduce = function(key, values){
        var result = {count: 0, host: ""};

        for(var i in values){
        result.count++;
        result.host = values[i].host;
        print(key+" : "+values[i]);
        }
        return result;
    }

when I write the above function on shell and the press Enter after completing, nothing gets printed on the shell. Is there anything else I should do to debug?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我纯我任性 2024-12-13 01:23:56

看起来reduce函数中的print()语句被写入日志文件,而不是shell。因此,请检查日志文件中的调试输出。

您可以在启动 mongod 进程时使用 --logpath D:\path\to\log.txt 参数指定日志文件。

It seems that print() statements in reduce functions are written to the log file, rather than the shell. So check your log file for your debug output.

You can specify the log file by using a --logpath D:\path\to\log.txt parameter when starting the mongod process.

ぃ双果 2024-12-13 01:23:56

看一下这个简单的在线 MongoDB MapReduce 调试器,它允许获取示例数据的聚合结果,并在浏览器开发环境中对 Map/Reduce/Finalize 函数执行逐步调试。

我希望它会有用。

http://targetprocess.github.io/mongo-mapreduce-debug-online/

Take a look at this simple online MongoDB MapReduce debugger which allows to get aggregation results on sample data as well as perform step-by-step debugging of Map / Reduce / Finalize functions right in your browser dev environment.

I hope it will be useful.

http://targetprocess.github.io/mongo-mapreduce-debug-online/

梦里人 2024-12-13 01:23:56

mongodb 网站上有一个专门的页面就是您的答案: http://www.mongodb .org/display/DOCS/Troubleshooting+MapReduce

显然你的reduce是错误的:result.count++行最终将包含数组值中包含的元素数量(在映射reduce范例中)没有任何意义。
您的reduce 函数只是返回一个“随机”主机名(因为mapreduce 算法在任何步骤中都无法预测reduce 内容)和一个随机数。

你能解释一下你想做什么吗?
(我的猜测是你想计算每个主机的“东西”的数量)

There is a dedicated page on the mongodb website which is your answer : http://www.mongodb.org/display/DOCS/Troubleshooting+MapReduce

and obviously your reduce is wrong : the line result.count++ will end up containing the number of elements contained in the array values which (in map reduce paradigm) does not mean anything.
Your reduce function is just returning a "random" hostname (because mapreduce algo is not predicable on the reduce content at any step) and a random number.

Can you explain what you want to do ?
(my guess would be that you want to count the number of "something" per host)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文