gpt4 book ai didi

mongodb - mongodb mapreduce中的where条件

转载 作者:行者123 更新时间:2023-12-05 08:44:35 25 4
gpt4 key购买 nike

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

我的数据是这样的

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

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

最佳答案

您可以在query 参数中进行。来自文档页面: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]
}
);

关于mongodb - mongodb mapreduce中的where条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5891228/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com