Workaround for N1QL* Queries in the .NET SDK

This blog was originally posted on David Ostrovsky's personal blog. To see to original blog post, click here

TL;DR: SELECT myBucket.* FROM myBucket

A change in the way N1QL returns results for star queries in Couchbase Server 4.1 seems to have broken how the .NET SDK deserializes the returned results. It causes the Query<> method to return the correct number of results, but with all properties at their default value. The reason is that a query like SELECT * FROM default default now produces the following JSON result:

As you can see, each document is returned as a property under the name of the bucket, whereas the .NET SDK implementation expects the results like they used to be in the earlier versions of N1QL, as an array of JSON document bodies:

Luckily, we can easily fix this by selecting the content of the defaultproperty instead of * in our query, like so: SELECT default.* FROM default which will now return the results in the format the .NET SDK expects.

Try it out and see that the Query<> method now returns objects with all the values correctly deserialized.

Share this article
Get Couchbase blog updates in your inbox
This field is required.

Author

Posted by David Ostrovsky, Senior Solutions Architect, Couchbase

David Ostrovsky is a Senior Solutions Architect at Couchbase. As a solutions architect, David worked with existing and potential Couchbase customers to design, implement and support deployments of Couchbase Server.

Leave a comment

Ready to get Started with Couchbase Capella?

Start building

Check out our developer portal to explore NoSQL, browse resources, and get started with tutorials.

Use Capella free

Get hands-on with Couchbase in just a few clicks. Capella DBaaS is the easiest and fastest way to get started.

Get in touch

Want to learn more about Couchbase offerings? Let us help.