2015-04-04 73 views
3

我想用couchbase npm包运行一些N1QL查询。下面是我在运行代码之前采取的步骤:使用node.js启用Couchbase N1QL引擎

  1. 安装并运行在OSX
  2. 导航到执行Couchbase:8091,并设置 了凭证以及该beer-sample
  3. 下载N1QL DP4到文件夹
  4. 启用cbq-engine像这样: ./cbq-engine -datastore=http://localhost:8091
  5. 创建一个primary index as per the documentation

在这一点上,我有localhost:8091(主要Couchbase群集)和localhost:8093(DP4引擎)都活着。

下面是我从Node.js的客户端使用,以试图运行一个简单的查询N1QL代码:

var colors = require('colors'); // for console.log 
var couchbase = require('couchbase'); 
var N1qlQuery = require('couchbase').N1qlQuery; // get query object 
var myCluster = new couchbase.Cluster('couchbase://localhost:8091'); // connect to live local cluster 
var myBucket = myCluster.openBucket(); // open bucket 
myBucket.enableN1ql(['http://localhost:8093/']); // enable n1ql as per documentation (http://docs.couchbase.com/developer/node-2.0/n1ql-queries.html) - I also tried :8091, same result 
var query = N1qlQuery.fromString('SELECT * FROM `beer-sample` LIMIT 10'); 

setTimeout(function() { 
    myBucket.query(query, function(err, res) { 
    if (err) { 
     console.log('query failed'.red, err); 
     return; 
    } 
    console.log('success!', res); 
    }); 
}, 2000); // just in case connecting takes a second or something? 

这里的结果:

query failed { [Error: failed to connect to bucket] code: 24 }

我似乎一切都试过我找不到任何文档来解决这个问题。这是怎么回事?

编辑:显然LCB_LOGLEVEL环境变量将允许底层C库抽出一些日志。它们是:

LCB_LOGLEVEL=5 node web.js 
0ms [I0] {1299} [INFO] (instance - L:372) Version=2.4.0, Changeset=0ac7fc4 
0ms [I0] {1299} [INFO] (instance - L:373) Effective connection string: couchbase://127.0.0.1/beer-sample. Bucket=beer-sample 
0ms [I0] {1299} [DEBUG] (instance - L:63) Adding host 127.0.0.1:8091 to initial HTTP bootstrap list 
0ms [I0] {1299} [DEBUG] (instance - L:63) Adding host 127.0.0.1:11210 to initial CCCP bootstrap list 
      Starting...    
107ms [I1] {1299} [INFO] (instance - L:372) Version=2.4.0, Changeset=0ac7fc4 
107ms [I1] {1299} [INFO] (instance - L:373) Effective connection string: couchbase://localhost:8091/default. Bucket=default 
107ms [I1] {1299} [DEBUG] (instance - L:63) Adding host localhost:8091 to initial CCCP bootstrap list 
107ms [I1] {1299} [DEBUG] (confmon - L:89) Preparing providers (this may be called multiple times) 
108ms [I1] {1299} [DEBUG] (confmon - L:99) Provider FILE is DISABLED 
108ms [I1] {1299} [DEBUG] (confmon - L:96) Provider CCCP is ENABLED 
108ms [I1] {1299} [DEBUG] (confmon - L:96) Provider HTTP is ENABLED 
108ms [I1] {1299} [DEBUG] (confmon - L:99) Provider MCRAW is DISABLED 
108ms [I1] {1299} [TRACE] (confmon - L:292) Start refresh requested 
108ms [I1] {1299} [TRACE] (confmon - L:271) Current provider is CCCP 
108ms [I1] {1299} [INFO] (cccp - L:118) Requesting connection to node localhost:8091 for CCCP configuration 
108ms [I1] {1299} [DEBUG] (lcbio_mgr - L:416) <localhost:8091> (HE=0x103803800) Creating new connection because none are available in the pool 
108ms [I1] {1299} [DEBUG] (lcbio_mgr - L:321) <localhost:8091> (HE=0x103803800) Starting connection on I=0x10311dc70 
108ms [I1] {1299} [INFO] (connection - L:441) <localhost:8091> (SOCK=0x10311da10) Starting. Timeout=2000000us 
110ms [I0] {1299} [DEBUG] (confmon - L:89) Preparing providers (this may be called multiple times) 
110ms [I0] {1299} [DEBUG] (confmon - L:99) Provider FILE is DISABLED 
110ms [I0] {1299} [DEBUG] (confmon - L:96) Provider CCCP is ENABLED 
110ms [I0] {1299} [DEBUG] (confmon - L:96) Provider HTTP is ENABLED 
110ms [I0] {1299} [DEBUG] (confmon - L:99) Provider MCRAW is DISABLED 
110ms [I0] {1299} [TRACE] (confmon - L:292) Start refresh requested 
110ms [I1] {1299} [TRACE] (connection - L:335) <localhost:8091> (SOCK=0x10311da10) Received completion handler. Status=0. errno=0 
110ms [I1] {1299} [INFO] (connection - L:116) <localhost:8091> (SOCK=0x10311da10) Connected 
110ms [I1] {1299} [DEBUG] (lcbio_mgr - L:271) <localhost:8091> (HE=0x103803800) Received result for I=0x10311dc70,C=0x10311da10; E=0x0 
110ms [I1] {1299} [DEBUG] (lcbio_mgr - L:223) <localhost:8091> (HE=0x103803800) Assigning R=0x10311da50 SOCKET=0x10311da10 
110ms [I1] {1299} [DEBUG] (ioctx - L:101) <localhost:8091> (CTX=0x100f012c0,unknown) Pairing with SOCK=0x10311da10 
110ms [I0] {1299} [TRACE] (confmon - L:271) Current provider is CCCP 
110ms [I0] {1299} [INFO] (cccp - L:118) Requesting connection to node 127.0.0.1:11210 for CCCP configuration 
110ms [I0] {1299} [DEBUG] (lcbio_mgr - L:416) <127.0.0.1:11210> (HE=0x10280e600) Creating new connection because none are available in the pool 
110ms [I0] {1299} [DEBUG] (lcbio_mgr - L:321) <127.0.0.1:11210> (HE=0x10280e600) Starting connection on I=0x100f01760 
110ms [I0] {1299} [INFO] (connection - L:441) <127.0.0.1:11210> (SOCK=0x100f01890) Starting. Timeout=2000000us 
110ms [I0] {1299} [TRACE] (connection - L:335) <127.0.0.1:11210> (SOCK=0x100f01890) Received completion handler. Status=0. errno=0 
110ms [I0] {1299} [INFO] (connection - L:116) <127.0.0.1:11210> (SOCK=0x100f01890) Connected 
110ms [I0] {1299} [DEBUG] (lcbio_mgr - L:271) <127.0.0.1:11210> (HE=0x10280e600) Received result for I=0x100f01760,C=0x100f01890; E=0x0 
110ms [I0] {1299} [DEBUG] (lcbio_mgr - L:223) <127.0.0.1:11210> (HE=0x10280e600) Assigning R=0x100f01540 SOCKET=0x100f01890 
110ms [I0] {1299} [DEBUG] (ioctx - L:101) <127.0.0.1:11210> (CTX=0x100d00ca0,unknown) Pairing with SOCK=0x100f01890 
110ms [I0] {1299} [DEBUG] (ioctx - L:151) <127.0.0.1:11210> (CTX=0x100d00ca0,sasl) Destroying. PND=0,ENT=1,SORC=1 
110ms [I0] {1299} [DEBUG] (ioctx - L:101) <127.0.0.1:11210> (CTX=0x10311dda0,unknown) Pairing with SOCK=0x100f01890 
110ms [I0] {1299} [DEBUG] (ioctx - L:151) <127.0.0.1:11210> (CTX=0x10311dda0,bc_cccp) Destroying. PND=0,ENT=1,SORC=1 
110ms [I0] {1299} [INFO] (lcbio_mgr - L:491) <127.0.0.1:11210> (HE=0x10280e600) Placing socket back into the pool. I=0x100f01760,C=0x100f01890 
111ms [I0] {1299} [INFO] (confmon - L:174) Setting new configuration. Received via CCCP 
111ms [I0] {1299} [DEBUG] (bootstrap - L:55) Instance configured! 
2112ms [I1] {1299} [ERROR] (negotiation - L:178) <localhost:8091> (SASLREQ=0x100f01180) Error: 0x17, Negotiation timed out 
2112ms [I1] {1299} [ERROR] (cccp - L:133) <NOHOST:NOPORT> Got I/O Error=0x17 
2112ms [I1] {1299} [INFO] (confmon - L:202) Provider 'CCCP' failed 
2112ms [I1] {1299} [DEBUG] (confmon - L:236) Will try next provider in 0us 
2112ms [I1] {1299} [DEBUG] (ioctx - L:151) <localhost:8091> (CTX=0x100f012c0,sasl) Destroying. PND=1,ENT=0,SORC=1 
2112ms [I1] {1299} [TRACE] (confmon - L:271) Current provider is HTTP 
2112ms [I1] {1299} [TRACE] (htconfig - L:395) Starting HTTP Configuration Provider 0x103875a00 
2112ms [I1] {1299} [ERROR] (htconfig - L:400) Not scheduling HTTP provider since no nodes have been configured for HTTP bootstrap 
2112ms [I1] {1299} [INFO] (confmon - L:202) Provider 'HTTP' failed 
2112ms [I1] {1299} [TRACE] (confmon - L:226) Maximum provider reached. Resetting index 
2112ms [I1] {1299} [ERROR] (bootstrap - L:100) Failed to bootstrap client=0x10311bb00. Code=0xa, Message=No more bootstrap providers remain 
query failed { [Error: failed to connect to bucket] code: 24 } 
10112ms [I0] {1299} [DEBUG] (lcbio_mgr - L:464) <127.0.0.1:11210> (HE=0x10280e600) Idle connection expired 

回答

1

而不是

myBucket.enableN1ql(['http://1.1.1.1:8093/']) 

myBucket.enableN1ql(['1.1.1.1:8093']) 

它为我工作。

1

couchbase://localhost:8091是错误的。您应该而不是指定服务器的初始端口,除非服务器正在侦听备用端口(并且服务器配置为这样做)。在这种情况下,如果备用端口是REST API,则指定http://方案,如果备用端口是数据(memcached)端口,则指定couchbase://

在内部,客户端可能按顺序连接到不同的端点类型(尝试更偏好于不太可取的类型)。