as docs say( https://github.com/cloudant/sync-android/blob/master/doc/query.md) im trying to do a query inside a list
look:
query.put("codigo", 4);
result = q.find(query);
for (DocumentRevision revision : result) {
Log.d("QueryTest", "Test1 :" + revision.getBody().toString());
}
return:
{ "codigo":4, "companies":[
{
"id":"b9f19d88-13c0-40e3-89de-63dc787afb4c", "name":"Filial 0 1488949817178" }, {
"id":"f17fb098-316e-4d33-a0f7-f5719bf9d62e", "name":"Filial 1 1488949817178" } ], "employees":[
{
"codigo":2891, "id":"cc54fa37-0b64-4108-869a-1303c6176ce5", "name":"Employee 0 79ed4" }, {
"codigo":4642, "id":"19b76bbc-82c7-4295-a385-82ac2d892458", "name":"Employee 1 e1102" } ], "id":"ef2d0ebf-50b9-4cd0-9aaf-5389bccaaa56", "nome":"Random 4" }
so its ok
but this query doesnt work:
query.put("employees.codigo", 2891);
first return:
QuerySqlTranslator: No single index contains all of [{employees.codigo={$eq=2891}}]; add index for these fields to query efficiently
after created the index:
Index i = q.createJsonIndex(Arrays.<FieldSort>asList(new FieldSort("employees.codigo")), null);
return
QueryExecutor: Projection fields array is empty, disabling project for this query
so i created the arraylist of fields to filter
List<String> fields = Arrays.asList("codigo");
result = q.find(query, 0 , 0 , fields, null);
nothing returned
adding more one field to filter:
query.put("codigo",4)
query.put("employees.codigo", 2891);
returned: Complain about index
Created another index:
i = q.createJsonIndex(Arrays.<FieldSort>asList(new FieldSort("employees.codigo"), new FieldSort("codigo")), null);
returned: Nothing
whats is wrong?
How can i get document by child and how can i get ONLY the children?
thanks
I think this is unsupported, see the doc on unsupported features, specifically the highlighted entry:
Arrays
- Dotted notation to index or query sub-documents in arrays.
- Querying for exact array match, { field: [ 1, 3, 7 ] }.
- Querying to match a specific array element using dotted notation, { field.0: 1 }.
- Querying using $all.
- Querying using $elemMatch.