0

I'm trying to find out the best way to get the type of a nested object in a couchbase document.

I have this document :

{
  "storeType": {
    "name": "Store"
  },
  "name": "Store",
  "_class": "common.domain.Store",
  "categories": [
    {
      "name": "Series",
      "displayable": false,
      "active": false,
      "highlights": [
        {
          "name": "Spiderman",
          "active": true
        },
        {
          "name": "Spiderman2",
          "active": true
        }
      ],
      "categoryId": "SERIES"
    }
  ],
  "storeId": "STORE::10",
  "order": 1
}

Spring data uses _class to find out the hole document type.

My question is :

How can I find the precise type of each object in categories list?

Thx a lot

Magmix
  • 13
  • 4
  • What is the type of the nested object in your example? – geraldss Sep 28 '16 at 15:35
  • Here I have a Store containing a list of categories (which is an inherited class) and each category has a list of highlights. – Magmix Sep 28 '16 at 16:08
  • Even with Spring Data I always add a type field to all my documents. It really helps. Also are you trying to get it through N1QL or a Spring Data repository? – Laurent Doguin Sep 28 '16 at 18:56
  • It's through N1QL. What we are doing typically is to use Spring Data for all simple queries and use the java client to perform more sophisticated queries (nested objects clearly). So far we have two issues : Updating a second level nested objects through N1QL and retriving the type of the nested object (to avoid parsing the N1qlQueryResult) – Magmix Sep 29 '16 at 08:25
  • Found the query to make the update. We used the collection operator WITHIN : UPDATE bucket b USE KEYS "Store::1" SET h.active = false FOR h WITHIN b.categories when h.cbHighlightId = "Highlight::1" END . Highlight is not a Document. – Magmix Sep 29 '16 at 15:08

1 Answers1

0

Found the query to make the update. We used the collection operator WITHIN : UPDATE bucket b USE KEYS "Store::1" SET h.active = false FOR h WITHIN b.categories when h.cbHighlightId = "Highlight::1" END . Highlight is not a Document

Magmix
  • 13
  • 4