【问题标题】:Update inner object in arangodb更新 arangodb 中的内部对象
【发布时间】:2015-05-27 12:44:52
【问题描述】:

我有一个存储在 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"
    }
  ]
}

我只想更改其中一种产品的库存价值

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

像 update store product stock less 1 where store 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

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

【问题讨论】:

    标签: arangodb aql


    【解决方案1】:

    找到答案

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

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

    【讨论】:

    • 我认为你是对的。将产品与商店分开存放是有意义的。这将允许轻松有效地更新单个产品(和商店)。如果商店及其所有产品如上所述包含在单个文档中,则每次产品更新都需要保存整个商店对象,这将变得非常低效。除此之外,将inStock 值存储为数字而不是使用字符串可能是有意义的。价格也是如此。
    猜你喜欢
    • 1970-01-01
    • 2019-05-25
    • 1970-01-01
    • 1970-01-01
    • 2020-12-12
    • 2018-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多