5

I have an object stored in arangodb which has additional inner objects, my current use case requires that I update just one of the elements.

Store Object

{
  "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"
    }
  ]
}

I want to change just one of the products stock value

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

Like update store product stock less 1 where store id = x, something to this effect

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

Apart from the above possibly it makes sense to store product as a separate document in collection store_products. I believe in NOSQL that is the best approach to reduce document size.

isawk
  • 969
  • 8
  • 21

1 Answers1

5

Found answer

here arangodb-aql-update-single-object-in-embedded-array and there arangodb-aql-update-for-internal-field-of-object

I however believe it is best to maintain separate documents and rather use joins when retrieving. Updates easily

Community
  • 1
  • 1
isawk
  • 969
  • 8
  • 21
  • I think you're right. Storing products separately from stores will make sense. That will allow updating individual products (and stores) easily and efficiently. If the store and all its products were contained in a single document as above, the whole store object would need to be saved for every product update, which will get very inefficient. Apart from that, it may make sense to store the `inStock` value as a number instead of using strings. The same applies for the prices. – stj May 27 '15 at 15:56