mongodb mapreduce 中的 where 条件

发布于 2024-11-05 14:08:19 字数 289 浏览 1 评论 0原文

如何在 mongos mapreduce 中指定条件,就像我们在 mongos group 函数中所做的那样。

我的数据就像

{lid:1000, age:23}, {lid:3000, age:23}, {lid:1000, age:24}. 

我只想发出值为 1000 的盖子。emit(this.lid, this.age)。但这将发出所有值。我想在这里有一个条件。地图减少有什么办法吗?我尝试在reduce函数中使用if条件进行过滤,但它不起作用

How do I specify a condition in mongos mapreduce as in we do in mongos group function.

My data is like

{lid:1000, age:23}, {lid:3000, age:23}, {lid:1000, age:24}. 

I want to emit only lid's having a value of 1000. emit(this.lid, this.age). But this will emit all values . I want to have a condition here. Is there any means in map reduce ? I tried to filter using an if condition in reduce function but its not working

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

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

发布评论

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

评论(2

孤独陪着我 2024-11-12 14:08:19

您可以在 query 参数中执行此操作。从文档页面: http://www.mongodb.org/display/DOCS/ MapReduce#MapReduce-概述

db.runCommand(
 { mapreduce : <collection>,
   map : <mapfunction>,
   reduce : <reducefunction>

   --> [, query : <query filter object>] <--

   [, sort : <sorts the input objects using this key. Useful for optimization, like sorting by the emit key for fewer reduces>]
   [, limit : <number of objects to return from collection>]
   [, out : <see output options below>]
   [, keeptemp: <true|false>]
   [, finalize : <finalizefunction>]
   [, scope : <object where fields go into javascript global scope >]
   [, verbose : true]
 }
);

You can do it in the query parameter. From the docs pages : http://www.mongodb.org/display/DOCS/MapReduce#MapReduce-Overview

db.runCommand(
 { mapreduce : <collection>,
   map : <mapfunction>,
   reduce : <reducefunction>

   --> [, query : <query filter object>] <--

   [, sort : <sorts the input objects using this key. Useful for optimization, like sorting by the emit key for fewer reduces>]
   [, limit : <number of objects to return from collection>]
   [, out : <see output options below>]
   [, keeptemp: <true|false>]
   [, finalize : <finalizefunction>]
   [, scope : <object where fields go into javascript global scope >]
   [, verbose : true]
 }
);
幻梦 2024-11-12 14:08:19

您的映射函数是一个 javascript 函数。您可以让它做任何您想做的事情,例如:

if (this.lid == 1000) emit(whatever);

Your mapping function is a javascript function. You can make it do anything your want, such as:

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