Bucket.query with using a view in nodejs SDK

Hi there,

I am trying to avoid parsing results returning from n1ql on your node.js SDK.

I am running a query that looks like this:

SELECT id, child.id FROM users;

I am getting a “duplicate id field” error from n1ql. The next fixes it

SELECT id, child.id as child_id FROM users;

But this returns the result in a flat json. That is not the proper construction of the data and I wish to have the json returned as:

id: …
child: {
id: …

I think that without this, you are giving the developers a world of pain as you virtually forcing them to cancel the DB architecture they chose. Is there any way to achieve this without mapping the query and the result and reverse engineer the result into a proper structure?


you could try this;
SELECT id, { “id”: child.id } as child_id FROM users;

N1QL provides this projection with arrays as well. just for kicks, here is a version with an embedded array;
SELECT id, [ child.id ] as child_id FROM users;


I am afraid I dont understand your answer.
Once you use “as” statement, how the result will return?
I=Would it still return as a flat array and not as sub-json