N1QL Select ALL (Select * from <bucketname>)

I am facing a problem with the N1QL when using the * (star) in the query which fetches all the fields of the document. The result of using such * in the query returns below -

I have highlighted the unwanted naming in the json structure. This happens only when I use the * in the query. If I uset he field names to define my result, then it does not add this name to the nodes.

It is really getting difficult to deserialize the json when this node name gets added.

Thanks,
Kris

3 Likes

Hi,

Please use

SELECT bucketname.* FROM bucketname;

4 Likes

Perfecto!!! Thats all I wanted.

3 Likes

One more question on the same line -

When I fire a N1QL query using the .NET SDK - Bucket.Query(“SELECT …”), I am able to receive the deserialized object back. Is there any option to get a plain json string as I see in your tutorial. Sometimes it is preferred to operate on the Json stream rather than doing a serialization & Deserialization.

Thanks,
Kris

@jmorris or @simonbasle might be able to help with that on .NET

I am actually getting the object and serializing it into string .NET. But its a kind of double processing. Couchbase SDK deserializes the json string and gives it to me as an object and then I do a serialization to change it back to string. Just thought of checking if there is any option to just get string output with the query.

Tks

I don’t think there is a way as is.
We extract the “result” part of the response into the Rows collection and let Json.NET do the mapping to the provided generic type. More accurately, we use Json.NET to map the entire response to a POCO that has a List<T> of rows for the results section.

Attempting to use string for T here instead of dynamic won’t cut it since in this case Json.NET expects a JSON string and finds a JSON object.

I’m not aware of a pseudo-type that could be used for T in order to bypass unmarshalling, but maybe Json.NET provides one? This would be outside the scope of the SDK though…

You can also use the N1QL REST API to get JSON strings. There is a section on the REST API in the N1QL documentation.