2016-11-29 4 views
1

mongoDBから5年間来て、今Couchbaseを勉強しています。私は都市別にグループ化し、すべてのmain.tempの値をフィールドに収集/プッシュするテストデータを持っています。これは$pushまたは$addToSetCouchbaseグループを名前で収集し、フィールド値を収集します

テストデータ

{ 
    "city": "a", 
    "main": { 
     temp: 1 
    } 
}, 
{ 
    "city": "a", 
    "main": { 
     temp: 2 
    } 
}, 
{ 
    "city": "b", 
    "main": { 
     temp: 3 
    } 
}, 
{ 
    "city": "b", 
    "main": { 
     temp: 4 
    } 
} 

私は結果は次のようになりたい、可能であれば、私はDESC/ASCに

を一時配列をソートすることにより、MongoDBの集計で行うことができます
{ 
    "city": "a", 
    "temp": [1, 2], 
}, 
{ 
    "city": "b", 
    "temp": [4, 3], 
}, 

私はadminからのguiクエリを使用して試しましたが、私が望む正確な結果を得られません。

select name, max(main.temp) as temp 
from weather103 
group by city 

答えて

1

[OK]を、私はCouchbaseのへようこそarray_agg

select city, array_agg(main.current_temp) as temp 
from weather103 
group by city 
order by temp desc 
+0

正しいと思われる、 分かりやすくするために、出力結果を添付してください。 –

0

@Hokutoseiを使用して、答えを得たと思います!

これらのリソースとチュートリアルをチェックして、クエリをすばやく始めることができます。 http://query.pub.couchbase.com/tutorial/#1 http://developer.couchbase.com/documentation/server/4.5/getting-started/first-n1ql-query.html

我々はまた、質問をする、かなりアクティブなフォーラムを持っています。 https://forums.couchbase.com/

+0

このチュートリアルでは、ありがとうございました。私はフォーラムを調べます。 – Hokutosei