26.NEST

NEST(巢)执行加入跨两个水桶。巢为每个左手生成一个对象的集合,而输入相应的右手被收集到一个对象集合.

可以替换示例中的NEST为JOIN 来对比不同

与 JOIN 类似, NEST 也支持 LEFT [ OUTER ] NEST.

Query:

 SELECT usr.personal_details, orders
    FROM users_with_orders usr 
        USE KEYS "Elinor_33313792" 
            NEST orders_with_users orders 
               ON KEYS ARRAY s.order_id FOR s IN usr.shipped_order_history END

结果:

{
  "results": [
    {
      "orders": [
        {
          "doc_type": "order",
          "order_details": {
            "order_datetime": "Wed Jun  6 18:53:39 2012",
            "order_id": "T103929516925"
          },
          "payment_details": {
            "payment_mode": "Debit Card",
            "total_charges": 308
          },
          "product_details": {
            "currency": "EUR",
            "list_price": 318,
            "pct_discount": 5,
            "product_id": "P3109994453",
            "sale_price": 303
          },
          "shipping_details": {
            "shipping_charges": 5,
            "shipping_status": "Delivered",
            "shipping_type": "Express"
          },
          "user_id": "Elinor_33313792"
        },
        {
          "doc_type": "order",
          "order_details": {
            "order_datetime": "Thu Aug 11 18:53:39 2011",
            "order_id": "T573145204032"
          },
          "payment_details": {
            "payment_mode": "NetBanking",
            "total_charges": 569
          },
          "product_details": {
            "currency": "GBP",
            "list_price": 666,
            "pct_discount": 15,
            "product_id": "P9315874155",
            "sale_price": 567
          },
          "shipping_details": {
            "shipping_charges": 2,
            "shipping_status": "Delivered",
            "shipping_type": "Regular"
          },
          "user_id": "Elinor_33313792"
        }
      ],
      "personal_details": {
        "age": 60,
        "display_name": "Elinor Ritchie",
        "email": "Elinor.Ritchie@snailmail.com",
        "first_name": "Elinor",
        "last_name": "Ritchie",
        "state": "Arizona"
      }
    }
  ]
}

Last updated

Was this helpful?