I have a VM running Ubuntu 14.04 LTS with DP4 of Couchbase 4 on it. I have manually started the couchbase query engine, like this:
/opt/couchbase/bin/cbq-engine -datastore=http://localhost:8091/pools
I can use the cbq tool and queries executed there work fine. However when I try to connect from the .NET SDK, things are not working.
Since I’m running the cbq engine from a remote shell (which I logged into via ssh) I can see that the client is not even hitting the query service (no log output on console).
A point of confusion to me is the way that the URI for the .Net sdk connection appears, at least from the samples, to be pointing only at the main port 8091 service, and not at the query service uri. Is there something I’m missing in my configuration so that the query service will resolve to a valid query service URI?
Code sample, based on Couchbase.N1QLExamples:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Couchbase.Core;
using Couchbase.Configuration.Client;
namespace Couchbase.N1QLExamples
{
class Program
{
static void Main(string[] args)
{
ClientConfiguration _config = new ClientConfiguration();
_config.Servers.Add(new Uri("http://192.168.1.122:8091/pools"));
//_config.BucketConfigs.Add(...);
var _cluster = new Cluster(_config);
int count = 0;
using (var bucket = _cluster.OpenBucket())
{
const string query = "SELECT count(*) AS COUNT FROM `beer-sample` ";
// const string query = "SELECT * FROM default";
Console.WriteLine(query);
var result = bucket.Query<dynamic>(query);
if (result.Metrics != null)
{
Console.WriteLine( "execution time: {0}", result.Metrics.ExecutionTime);
}
foreach (var row in result.Rows)
{
Console.WriteLine(row);
count++;
}
if (count == 0)
{
Console.WriteLine("No rows found."); // This just as probably means the query is invalid, as any other thing. Welcome to the wild world of NoSQL.
}
else
{
Console.WriteLine("%d rows found", count);
}
}
_cluster.Dispose();
Console.Read();
}
}
}
I expected an error, and I get no error, just a silent zero row result.
If I remove the _config.Servers.Add(new Uri(“http://192.168.1.122:8091/pools”)) then the SDK also silently fails, presumably after trying to talk to the query service on localhost, and not finding one there. I do not much like the idea that configuring an invalid URI, or using a default URI, will just silently result in all queries returning zero results, and SUCCEEDING.