2017-04-20 11 views
0

の分私のJSONデータ取得:DocumentDBはサブアレー

[ 
    { 
    "Code": "GB-00001", 
    "BasicInformation": { 
     "WGS84Longitude": -4.670000, 
     "WGS84Latitude": 50.340000 
    }, 
    "Availability": [{ 
      "ArrivalDate": "2017-04-21", 
      "Price": 689 
     }, 
     { 
      "ArrivalDate": "2017-04-28", 
      "Price": 1341 
     } 
    ]}, 
    { 
    "Code": "GB-00002", 
    "BasicInformation": { 
     "WGS84Longitude": -4.680000, 
     "WGS84Latitude": 50.350000 
    }, 
    "Availability": [{ 
      "ArrivalDate": "2017-04-21", 
      "Price": 659 
     }, 
     { 
      "ArrivalDate": "2017-04-28", 
      "Price": 1440 
     } 
    ]} 
}] 

私はのようになり、結果が欲しい:

[ 
{ 
    "HouseCode": "GB-00001", 
    "Country": "GB", 
    "location": { 
     "type": "Point", 
     "coordinates": [ 
      50.340000, 
      -4.670000 
     ] 
    }, "lowestPrice": 689 
}, 
{ 
    "HouseCode": "GB-00002", 
    "Country": "GB", 
    "location": { 
     "type": "Point", 
     "coordinates": [ 
      50.350000, 
      -4.680000 
     ] 
    }, "lowestPrice" : 659 
} 

私の問題は、次のとおりです。min(c.Availability.Price)

これを使用する方法私の現在の質問は、ポイントに変換するlat lngですが、最低/最低価格を取得する方法は考えていません。

SELECT c.Code, c.BasicInformation.Country , 
    {"type":"Point","coordinates": [c.BasicInformation.Latitude, c.BasicInformation.Longitude]} as location 
FROM c 

はすでに、おそらく私は早すぎるよJoin c.Availability a, min(a.Price)

編集てみましたか? https://feedback.azure.com/forums/263030-documentdb/suggestions/18561901-add-group-by-support-for-aggregate-functions url in https://stackoverflow.com/a/42697673/169714

答えて

2

これは、ユーザー定義関数(UDF)の理想的な状況に非常に近いです。ここで

はトリックを行う必要がありますいずれかになります。

function lowestPrice(availability) { 
    var i, len, lowest, row; 
    lowest = 2e308; 
    for (i = 0, len = availability.length; i < len; i++) { 
    row = availability[i]; 
    lowest = Math.min(lowest, row.Price); 
    } 
    return lowest; 
}; 

あなたはこのようにそれを呼び出す:

SELECT 
    c.Code, 
    c.BasicInformation.Country, 
    {"type":"Point","coordinates": [ 
    c.BasicInformation.Latitude, c.BasicInformation.Longitude 
    ]} as location, 
    udf.lowestPrice(c.Availability) as lowestPrice 
FROM c 
+0

集計関数を使用するときにグループ化が不十分で、ユーザー定義関数を作成する必要があるため、min(a.Price)を使用できません。私は前にudfを使ったことがないので、私はそれを調べて、これに戻ります。あなたの答えをありがとう。編集:クラッシュhttp://imgur.com/a/hxoJ9 –

+0

スクリーンショットは英語ではありません –

+0

これは単なる通常のWindowsメッセージです。 DocumentDB.GatewayService.exeが機能しなくなりました。 –

1

私の知る限り、あなただけの今のあなたの条件を達成するためにUDFを使用することができます。また、私はラリーMaccheroneによって提供されたコードをチェックして、それはAzureのDocumentDBサービスと私のDocumentDBエミュレータ(バージョン1.11.136.2)の両方の仕事を次の可能性があるので:

enter image description here

DocumentDB.GatewayService.exeが動作を停止しました

DocumentDB.GatewayServiceクラッシュについては、ダンプファイルを収集し、電子メールで[email protected]に添付する必要があると想定しました。詳細は、DocumentDB Emulator troubleshootingを参照してください。

+0

ありがとう!私はそれらを郵送しました。 –