Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update inner object in arangodb

Tags:

arangodb

aql

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.

like image 516
isawk Avatar asked May 27 '15 12:05

isawk


1 Answers

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

like image 147
isawk Avatar answered Oct 24 '22 08:10

isawk