N1QL on Windows not working with Internal Error


#1

Latest Couchbase server installed and tested working for inserts from a test Node.js script.

Now I’m trying to run queries with N1QL.

I’ve extracted the N1QL Developer Preview 3 to c:\developer_preview_3 and can successfully run the tutorial.

I then close the tutorial command prompt (necessary to free up the port 8093) and open another command prompt and run cbq-engine in it like:

C:\couchbase_dev_preview_3>cbq-engine -couchbase http://localhost:8091/

I then open another command prompt to run cbq and I get the following results:

C:\couchbase_dev_preview_3>CBQ
CBQ> SELECT * FROM beer-sample
{
    "error":
        {
            "caller": "view_index:200",
            "code": 5000,
            "key": "Internal Error",
            "message": "Bucket beer-sample not found."
        }
}
CBQ> SELECT * FROM notrealbucket
{
    "error":
        {
            "caller": "standard:69",
            "cause": "Bucket notrealbucket does not exist",
            "code": 5000,
            "key": "Internal Error",
            "message": "Optimizer Error"
        }
}
CBQ>

So I get an internal error that says “not found” for a bucket at does in fact exist, and an internal error that says “Optimizer Error” for a bucket that does not exist.

Also, errors are printed out on my running cbq-engine process:

C:\couchbase_dev_preview_3>cbq-engine -couchbase http://localhost:8091/
04:51:31.720722 Info line disabled false
04:51:31.742723 tuqtng started...
04:51:31.743723 version: v0.7.2
04:51:31.745723 site: http://localhost:8091/
04:51:47.468638 ←[31mERROR: Unable to access view - cause: error executing view req at http://127.0.0.1:8092/beer-sample/_all_docs?limit=1001: 400 Bad Request -
 {"error":"bad_request","reason":"_all_docs is no longer supported"}
←[0m←[2m -- couchbase.(*viewIndex).ScanRange() at view_index.go:186←[0m
04:51:47.469638 Checking bucket URI: /pools/default/buckets/beer-sample?bucket_uuid=27e71c5f06fea74e37ef2c1501a0ffe2
04:51:47.470639 ←[31mERROR: Get /pools/default/buckets/beer-sample?bucket_uuid=27e71c5f06fea74e37ef2c1501a0ffe2: unsupported protocol scheme ""←[0m←[2m -- couch
base.(*viewIndex).ScanRange() at view_index.go:192←[0m

So what’s going on here?

Additionally, when attempting to do an N1QL query from a Node.js app (via couchnode), I get the following error thrown upon attempting to execute a (simple) query which can be found below this error printout:

C:\git\7\savetodb.js:42
                                        throw err; //@TODO
                                              ^
Error: lcb error undefined
    at Bucket._invoke (C:\git\7\node_modules\couchbase\lib\bucket.js:709:25)
    at Bucket._maybeInvoke (C:\git\7\node_modules\couchbase\lib\bucket.js:726:10)
    at Bucket.query (C:\git\7\node_modules\couchbase\lib\bucket.js:617:10)
    at Bucket.<anonymous> (C:\git\7\savetodb.js:36:18)
    at Bucket.emit (events.js:117:20)
    at Bucket.<anonymous> (C:\git\7\node_modules\couchbase\lib\bucket.js:178:10)

The code I use to execute the query is:

		var query1 = N1qlQuery.fromString("SELECT 'Hello World' AS Greeting");
		bucketMessages.query(
			query1,
			function(err, arrMessageHighestUID) {

				if (err) {
					console.log("\n\n***Error in function(err, objMessageHighestUID)...\n\n");
					throw err; //@TODO
				}
			}
		);

Is the problem I’m having with my code’s query the same problem I’m having with CBQ?

  • Austin

#2

Hi, I’ll start with basics: do you have the beer-sample bucket installed? you can go to localhost:8091 > under data buckets tab to check to see if beer sample is created and is healthy (green)


#3

Hi neatcode,
For the error you described - “Bucket beer-sample not found” -
Try this:

From the instructions in the N1QL page :
Step 5: Before issuing queries against a Couchbase bucket,
run the following command from the query command line:

CREATE PRIMARY INDEX ON [bucket-name]

In your case this would be:
CREATE PRIMARY INDEX ON beer-sample


#4

That fixed it for CBQ, and I can now query beer-sample using N1ql in CBQ.

However, I still cannot perform N1ql queries from my Node.js application (although I can do standard inserts). The following error is produced:

C:\git\7>node savetodb.js



Couchbase Connected
here


***Error in function(err, objMessageHighestUID)...



C:\git\7\savetodb.js:42
                                        throw err; //@TODO
                                              ^
Error: lcb error undefined
    at Bucket._invoke (C:\git\7\node_modules\couchbase\lib\bucket.js:709:25)
    at Bucket._maybeInvoke (C:\git\7\node_modules\couchbase\lib\bucket.js:726:10)
    at Bucket.query (C:\git\7\node_modules\couchbase\lib\bucket.js:617:10)
    at Bucket.<anonymous> (C:\git\7\savetodb.js:36:18)
    at Bucket.emit (events.js:117:20)
    at Bucket.<anonymous> (C:\git\7\node_modules\couchbase\lib\bucket.js:178:10)

My code is:

var config = {
    connstr : "http://localhost:8091",
    bucket : 'beer-sample',
    "operationTimeout": 5000,
    "queryhosts": "127.0.0.1:8093"
}

… and …

var cb = new couchbase.Cluster(config.connstr);
var bucketMessages = cb.openBucket(config.bucket);

bucketMessages.on('connect', function(err) {
	if(err) {
		console.error("Failed to connect to cluster: " + err);
		process.exit(1);
	}

	var query1 = N1qlQuery.fromString("SELECT * FROM beer-sample LIMIT 2");
	bucketMessages.query(
		query1,
		function(err, arrMessageHighestUID) {

			if (err) {
				console.log("\n\n***Error in function(err, objMessageHighestUID)...\n\n");
				throw err; //@TODO
			}
		}	
	);
});


#5

Ok figured out that problem.

Added:

bucketMessages.enableN1ql(config.queryhosts);

after

var bucketMessages = cb.openBucket(config.bucket);

in the code I posted. This eliminated the “lcb” error and allowed me to perform N1ql queries.

Is this bucket.enableN1ql("127.0.0.1:8093") function documented anywhere other than being buried in the API Reference?


#6

Hey neatcode,

Please ensure you are using the latest Node.js SDK and have properly established a bucket connection prior to querying. The error you are encountering indicates that a connection could not be established with the cluster.

Cheers, Brett


#7

Brett,

I am using the latest Node.js SDK and was properly connected to the cluster fine before querying and verified this by successfully doing inserts on the bucket.

The error was triggered when I wasn’t using .enableN1ql() on the bucket, which seems to be only mentioned (buried) in the API Reference. After I added .enableN1ql("127.0.0.1:8093") to the bucket, the lcb error you are talking about went away.

– Austin


#8

Hey neatcode,

This is remarkably odd as the N1QL querying system does not actually use libcouchbase whatsoever! I appologize for any confusion, and I hope to be able to remove the necessity of enableN1ql soon!

Cheers, Brett