Collection projection

How can I project a nested object in lookupIn and n1ql ?

I the following document

{
  "foo":{
    "bar":{
      "a":1,
      "b":2,
      "c":3
    },
    "baz":{
      "a":4,
      "b":5
    }
  }
}

How we can select foo.*.a ?

{
  "foo":{
    "bar":{
      "a":1
    },
    "baz":{
      "a":4
    }
  }
}

You can’t use * in the middle. you need to provide explicit name or Use * at the end

I know, but how can I select it??( project a field)

I have a map of objects , my objects has large parts, I just need to select some fields

You need to construct Object according to requirements.

   insert into default values("1",{ "bar":{ "a":1, "b":2, "c":3 }, "baz":{ "a":4, "b":5 } }); 
   SELECT OBJECT v.name: {v.val.a} FOR v IN  OBJECT_PAIRS(d)  END AS obj 
    FROM default d;

What about bucket.lookupIn.get?

I am not expert in that area cc @ingenthr. Most probably you need to get whole document and select in SDKs or use subdoc API to get specific paths.

@vsr1 I found that foo[*].a works for arrays, but I don’t found for objects
Where is foo[*].a document? I found it by try and fail

If array you can use foo[*].a because it subscripts, not for objects which needs fields.

https://docs.couchbase.com/server/6.0/n1ql/n1ql-language-reference/arrayfun.html#fn-array-star

The Sub-Document API cannot do this iteration and processing. I believe it may be possible to do this with JSONPath. You can probably also build an index inclusive of projection in this case with Couchbase Views in javascript.