RethinkDB Multiple 在 Map 中发出
RethinkDB Multiple emits in Map
我已经试用 RethinkDB 一段时间了,但我仍然不知道如何做这样的事情 MongoDB 示例:
在 Mongo 中,在 map 函数中,我可以迭代一个文档的数组字段,并发出多个值。
我不知道如何设置要在 map 中发出的键或 return map 函数中每个文档的多个值。
例如,我想从中得到:
{
'num' : 1,
'lets': ['a','b,'c']
}
到
[
{'num': 1, 'let' : 'a' },
{'num': 1, 'let' : 'b' },
{'num': 1, 'let' : 'c' }
]
我不确定我是否应该在 RethinkDB 中以不同的方式思考这个问题,或者使用不同于 map-reduce 的东西。
谢谢。
我不熟悉Mongo;直接处理您的转换示例:
r.expr({
'num' : 1,
'lets': ['a', 'b', 'c']
})
.do(function(row) {
return row('lets').map(function(l) {
return r.object(
'num', row('num'),
'let', l
)
})
})
当然,您可以使用 map()
而不是 do()
(如果不是单个对象)
我已经试用 RethinkDB 一段时间了,但我仍然不知道如何做这样的事情 MongoDB 示例:
在 Mongo 中,在 map 函数中,我可以迭代一个文档的数组字段,并发出多个值。
我不知道如何设置要在 map 中发出的键或 return map 函数中每个文档的多个值。
例如,我想从中得到:
{
'num' : 1,
'lets': ['a','b,'c']
}
到
[
{'num': 1, 'let' : 'a' },
{'num': 1, 'let' : 'b' },
{'num': 1, 'let' : 'c' }
]
我不确定我是否应该在 RethinkDB 中以不同的方式思考这个问题,或者使用不同于 map-reduce 的东西。
谢谢。
我不熟悉Mongo;直接处理您的转换示例:
r.expr({
'num' : 1,
'lets': ['a', 'b', 'c']
})
.do(function(row) {
return row('lets').map(function(l) {
return r.object(
'num', row('num'),
'let', l
)
})
})
当然,您可以使用 map()
而不是 do()
(如果不是单个对象)