Skip to content

Instantly share code, notes, and snippets.

@Realetive
Created September 13, 2019 08:06
Show Gist options
  • Save Realetive/02f1f0623f247d19e670f2fe462eb79c to your computer and use it in GitHub Desktop.
Save Realetive/02f1f0623f247d19e670f2fe462eb79c to your computer and use it in GitHub Desktop.
Есть выборка из БД списка заказов. В каждом заказе есть products[].options[].tickets с количеством билетов и products[].product.directions[].ticket с параметрами каждого из билетов. Нужно так обойти граф, чтобы собрать общую статистику по каждому типу билетов: их суммарном количестве и стоимости.
[
{
"_id": {
"$oid": "5d49a871e8a893003da5aae7"
},
"products": [
{
"key": "8900a49ddca428441cab91c14e9cf85f580cfdc2",
"product": {
"_id": "cfzISQI39vvEyEH3XJV0Ru",
"directions": [
{
"_key": "07401420ebdb",
"tickets": [
{
"_key": "b77eeb1fb6ef",
"category": {
"_id": "0a9d8fed-260c-4c2f-9125-d30c5b3f0934",
"title": "Стандарт"
},
"name": "Взрослый",
"price": "880",
"ticket": [
{
"_id": "5425f56b-2480-4f7d-8383-02b710b0630f",
"_type": "ticketType",
"name": {
"_type": "slug",
"current": "adult"
},
"title": "Взрослый"
}
]
},
{
"_key": "481afdaa81da",
"category": {
"_id": "0a9d8fed-260c-4c2f-9125-d30c5b3f0934",
"title": "Стандарт"
},
"name": "Дошкольный (до 3-х лет)",
"price": "0",
"ticket": [
{
"_id": "960e8dc9-3924-4244-bfd8-73af0dd05469",
"_type": "ticketType",
"name": {
"_type": "slug",
"current": "free"
},
"title": "Бесплатный"
}
]
}
]
}
]
},
"options": [
{
"number": "644203",
"direction": "07401420ebdb",
"tickets": {
"b77eeb1fb6ef": {
"$numberInt": "1"
},
"481afdaa81da": {
"$numberInt": "0"
}
},
"event": {
"_key": "5adaaf74-104e-478d-a027-7d3a96901a77",
"start": "2019-09-29T21:20:00.000Z"
}
}
]
}
]
},
{
"_id": {
"$oid": "5d49a8f8e8a893003da5aae9"
},
"products": [
{
"key": "8900a49ddca428441cab91c14e9cf85f580cfdc2",
"product": {
"_id": "cfzISQI39vvEyEH3XJV0Ru",
"directions": [
{
"_key": "07401420ebdb",
"tickets": [
{
"_key": "b77eeb1fb6ef",
"category": {
"_id": "0a9d8fed-260c-4c2f-9125-d30c5b3f0934",
"title": "Стандарт"
},
"name": "Взрослый",
"price": "990",
"ticket": [
{
"_id": "5425f56b-2480-4f7d-8383-02b710b0630f",
"_type": "ticketType",
"api": [
{
"_key": "4acf68f45453",
"provider": {
"_ref": "584d02b7-6034-439c-b014-f771dff701c2",
"_type": "reference"
},
"value": "adult"
}
],
"name": {
"_type": "slug",
"current": "adult"
},
"title": "Взрослый"
}
]
},
{
"_key": "481afdaa81da",
"category": {
"_id": "0a9d8fed-260c-4c2f-9125-d30c5b3f0934",
"title": "Стандарт"
},
"name": "Дошкольный (до 3-х лет)",
"price": "100",
"ticket": [
{
"_id": "960e8dc9-3924-4244-bfd8-73af0dd05469",
"_type": "ticketType",
"name": {
"_type": "slug",
"current": "free"
},
"title": "Бесплатный"
}
]
}
]
}
]
},
"options": [
{
"number": "121932",
"direction": "07401420ebdb",
"tickets": {
"b77eeb1fb6ef": {
"$numberInt": "1"
},
"481afdaa81da": {
"$numberInt": "0"
}
},
"event": {
"_key": "5adaaf74-104e-478d-a027-7d3a96901a77",
"start": "2019-09-29T21:20:00.000Z"
}
}
]
}
]
},
{
"_id": {
"$oid": "5d5e52df7ca8f8003dab181a"
},
"products": [
{
"key": "7d9a81c06cdf8505140359732ec000c6b619cf8f",
"product": {
"_id": "cfzISQI39vvEyEH3XJV0Ru",
"directions": [
{
"_key": "07401420ebdb",
"tickets": [
{
"_key": "d39b5887b542",
"category": {
"_id": "0a9d8fed-260c-4c2f-9125-d30c5b3f0934",
"title": "Стандарт"
},
"name": "Взрослый",
"price": "990",
"ticket": [
{
"_id": "5425f56b-2480-4f7d-8383-02b710b0630f",
"_type": "ticketType",
"name": {
"_type": "slug",
"current": "adult"
},
"title": "Взрослый"
}
]
},
{
"_key": "46bc0458250e",
"category": {
"_id": "0a9d8fed-260c-4c2f-9125-d30c5b3f0934",
"title": "Стандарт"
},
"name": "Дошкольный (до 3-х лет)",
"price": "0",
"ticket": [
{
"_id": "960e8dc9-3924-4244-bfd8-73af0dd05469",
"_type": "ticketType",
"name": {
"_type": "slug",
"current": "free"
},
"title": "Бесплатный"
}
]
}
]
}
]
},
"options": [
{
"number": "156296",
"direction": "07401420ebdb",
"tickets": {
"d39b5887b542": {
"$numberInt": "2"
},
"46bc0458250e": {
"$numberInt": "2"
}
},
"event": {
"_key": "9460ee8f-47b8-439f-b1e2-f350aacac537",
"start": "2019-09-29T21:20:00.000Z"
}
}
]
}
]
}
]
{
"tickets": [
{
"_key": "b77eeb1fb6ef",
"category": {
"_id": "0a9d8fed-260c-4c2f-9125-d30c5b3f0934",
"title": "Стандарт"
},
"name": "Взрослый",
"count": 4,
"sum": 1480
},
{
"_key": "481afdaa81da",
"category": {
"_id": "0a9d8fed-260c-4c2f-9125-d30c5b3f0934",
"title": "Стандарт"
},
"name": "Дошкольный (до 3-х лет)",
"count": 3,
"sum": 200
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment