Using Arrays in Index Paths

Index paths can contain arrays, but certain rules apply.

Before Mobile SDK 4.1, index paths supported only maps—in other words, dictionaries or associative arrays. For example, in a path such as a.b.c, SmartStore required both b and c to be maps. Otherwise, when evaluating the path, SmartStore returned nothing.

In Mobile SDK 4.1 and later, index paths can contain arrays and maps. In the a.b.c example, if the value of b is an array, SmartStore expects the array to contain maps that define c. SmartStore then returns an array containing values of c keys found in the b array’s maps.

You can’t use index paths that traverse arrays with JSON1 index specs.

Note

Example

The following table shows various examples of a.b.c paths and the values returned by a SmartStore query.

Description Example soup element Value for path a.b.c
No arrays
1{ 
2    "a":{ 
3        "b":{ "c":1 } 
4    } 
5}
1
c points to an array (internal node).
1{  
2   "a":{  
3      "b":{  
4         "c":[1,2,3]
5      }
6   }
7}
1[  
2   1,
3   2,
4   3
5]
b points to an array of maps. Some maps contain the c key. Other maps are ignored.
1{  
2   "a":{  
3      "b":[  
4         {  
5            "c":1
6         },
7         {  
8            "c":2
9         },
10         {  
11            "no-c":3
12         }
13      ]
14   }
15}
1[  
2   1,
3   2
4]
a points to an array of maps. In some maps, b points to a map containing a key. In other maps, b points to an array of maps. Only values from c keys are returned.
1{  
2   "a":[  
3      {  
4         "b":{  
5            "c":0
6         }
7      },
8      {  
9         "b":[  
10            {  
11               "c":1
12            },
13            {  
14               "c":2
15            },
16            {  
17               "no-c":3
18            }
19         ]
20      }
21   ]
22}
1[  
2   0,
3   [  
4      1,
5      2
6   ]
7]