【发布时间】:2012-03-02 00:35:15
【问题描述】:
在我看来,我尝试发出 postal_country,但我不知道如何在 erlang 中完成。
这是我的文档的结构:
{
...
"postal_address": {
"postal_country": "BE"
...
}
}
这是我要翻译的js:
function(doc) {
if (doc['ruby_class'] == 'Company' && doc['postal_address']['postal_country']) {
emit(doc['postal_address']['postal_country'], 1)
}
}
这是我在 erlang 中尝试过的:
fun({Doc}) ->
case proplists:get_value(<<"ruby_class">>, Doc) of
<<"Company">> ->
Addr = proplists:get_value(<<"postal_address">>, Doc, null),
Key = proplists:get_value(<<"postal_country">>, Addr, null),
Emit(Key, 1);
_ ->
ok
end
end.
【问题讨论】:
-
这个函数有错误吗? Emit 似乎是一个未绑定的变量...
-
(仅供参考 @Isac Emit 是 CouchDB 的一个函数:他正在编写一个 CouchDB 映射函数)