Workaround for N1QL * queries in the .NET SDK

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 now produces the following JSON result:

[
  {
    "default": {
      "prop1": "...",
      "prop2": "..."
    }
  },
  {
    "default": {
      "prop1": "...",
      "prop2": "..."
    }
  }
]

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:

[
  {
    "prop1": "...",
    "prop2": "...",
  },
  {
    "prop1": "...",
    "prop2": "...",
  }
]

Luckily, we can easily fix this by selecting the content of the default property 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.

David Ostrovsky

I'm a level 38 Computer Geek, with experience in everything from databases to mobile apps. I'm also a Senior Solutions Architect at Couchbase, where I often keep clients happy by coding hard.

comments powered by Disqus