如何在MongoDB Map-reduce映射函数中使用变量 [英] How to use variables in MongoDB Map-reduce map function

查看:102
本文介绍了如何在MongoDB Map-reduce映射函数中使用变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

提供文档

{_id:110000, groupings:{A:'AV',B:'BV',C:'CV',D:'DV'},coin:{old:10,new:12}}

我的规范要求在运行时指定用于映射和聚合的属性,因为用户感兴趣的分组不是预先知道的,而是由用户在运行时指定的.

My specs call for the specification of attributes for mapping and aggregation at run time, as the groupings the user is interested in are not known up front, but specified by the user at runtime.

例如,一个用户将指定[A,B],这将导致映射排放量

For example, one user would specify [A,B] which will cause mapping emissions of

emit( {A:this.groupings.A,B:this.groupings.B},this.coin )

而另一个人想要指定[A,C],这将导致映射排放物

while another would want to specify [A,C] which will cause mapping emissions of

emit( {A:this.groupings.A,C:this.groupings.C},this.coin )

B/c映射器和化简器函数在服务器端执行,并且无法访问客户端变量,我无法提出一种在映射器函数中使用变量映射键的方法.

B/c the mapper and reducer functions execute server side, and don't have access to client variables, I haven't been able to come up with a way to use a variable map key in the mapper function.

如果我可以从map函数的执行范围中引用要分类的事物列表,那么这一切都非常简单.但是,b/c映射功能最终会从不同的范围获取这些信息,我不知道该怎么做,或者甚至可能.

If I could reference a list of things to group by from the scope of the execution of the map function, this is all very straightforward. However, b/c the mapping function ends up getting these from a different scope, I don't know how to do this, or if it's even possible.

在我开始尝试动态构建通过驱动程序执行的Java脚本之前,还有人有更好的建议吗?也许分组"功能可以更好地处理这种情况?

Before I start trying to dynamically build java script to execute through the driver, does anyone have a better suggestion? Maybe a 'group' function will handle this scenario better?

推荐答案

您可以使用map-reduce命令上的"scope"参数将全局只读数据传递到map-reduce函数中.恐怕它没有很好的记录.

You can pass global, read-only data into map-reduce functions using the "scope" parameter on the map-reduce command. It's not very well documented, I'm afraid.

这篇关于如何在MongoDB Map-reduce映射函数中使用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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