更新arangodb中的内部对象

时间:2015-05-27 12:44:53

标签: arangodb aql

我有一个存储在arangodb中的对象,它有额外的内部对象,我当前的用例要求我只更新其中一个元素。

存储对象

@config

我想更改其中一个产品库存值

{
  "status": "Active",
  "physicalCode": "99999",
  "postalCode": "999999",
  "tradingCurrency": "USD",
  "taxRate": "14",
  "priceVatInclusive": "No",
  "type": "eCommerce",
  "name": "John and Sons inc",
  "description": "John and Sons inc",
  "createdDate": "2015-05-25T11:04:14+0200",
  "modifiedDate": "2015-05-25T11:04:14+0200",
  "physicalAddress": "Corner moon and space 9 station",
  "postalAddress": "PO Box 44757553",
  "physicalCountry": "Mars Sector 9",
  "postalCountry": "Mars Sector 9",
  "createdBy": "john.doe",
  "modifiedBy": "john.doe",
  "users": [
    {
      "id": "577458630580",
      "username": "john.doe"
    }
  ],
  "products": [
    {
      "sellingPrice": "95.00",
      "inStock": "10",
      "name": "School Shirt Green",
      "code": "SKITO2939999995",
      "warehouseId": "723468998682"
    },
    {
      "sellingPrice": "95.00",
      "inStock": "5",
      "name": "School Shirt Red",
      "code": "SKITO245454949495",
      "warehouseId": "723468998682"
    },
    {
      "sellingPrice": "95.00",
      "inStock": "10",
      "discount": "5%",
      "name": "School Shirt Blue",
      "code": "SKITO293949495",
      "warehouseId": "723468998682"
    }
  ]
}

就像更新商店产品库存减去1商店ID = x,这是有效的

{
  "sellingPrice": "95.00",
  "inStock": "10",
  "discount": "5%",
  "name": "School Shirt Blue",
  "code": "SKITO293949495",
  "warehouseId": "723468998682"
}

除了以上可能,将产品作为单独的文档存储在集合store_products中是有意义的。我相信NOSQL是减少文档大小的最佳方法。

1 个答案:

答案 0 :(得分:5)

找到答案

这里arangodb-aql-update-single-object-in-embedded-array就在那里 arangodb-aql-update-for-internal-field-of-object

但我认为最好保留单独的文档,而不是在检索时使用连接。轻松更新