更新arangodb中的内部对象

isw*_*wak 5 arangodb aql

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

存储对象

{
  "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"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

我想改变其中一个产品的股票价值

{
  "sellingPrice": "95.00",
  "inStock": "10",
  "discount": "5%",
  "name": "School Shirt Blue",
  "code": "SKITO293949495",
  "warehouseId": "723468998682"
}
Run Code Online (Sandbox Code Playgroud)

就像更新商店产品库存少于1,其中商店id = x,这样的效果

FOR store IN stores
    FILTER store._key == "837108415472"
    FOR product IN store.products 
        FILTER product.code == "SKITO293949495"
    UPDATE product WITH { inStock: (product.inStock - 1) } IN store.products
Run Code Online (Sandbox Code Playgroud)

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

isw*_*wak 5

找到答案

这里是arangodb-aql-update-single-object-in-embedded-array,还有 arangodb-aql-update-for-internal-field-of-object

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