Javascript 结果,而不是可能不存在的行。您的代码是client.execute(query,function(err,result))--因此,如果client.execute与大多数数据库查询函数一样工作,那么如果没有错误,查询的结果将进入result。您想测试if

Javascript 结果,而不是可能不存在的行。您的代码是client.execute(query,function(err,result))--因此,如果client.execute与大多数数据库查询函数一样工作,那么如果没有错误,查询的结果将进入result。您想测试if,javascript,node.js,Javascript,Node.js,结果,而不是可能不存在的行。您的代码是client.execute(query,function(err,result))--因此,如果client.execute与大多数数据库查询函数一样工作,那么如果没有错误,查询的结果将进入result。您想测试if(result.length==0)。执行if(row.length==0){`关闭节点并给我这个错误…TypeError:无法读取/home中未定义的属性'length'…让它工作了!didif(result.rows.length==0){

结果,而不是可能不存在的行。您的代码是client.execute(query,function(err,result))--因此,如果client.execute与大多数数据库查询函数一样工作,那么如果没有错误,查询的结果将进入result。您想测试if(result.length==0)。执行
if(row.length==0)
{`关闭节点并给我这个错误…
TypeError:无法读取/home中未定义的属性'length'
…让它工作了!did
if(result.rows.length==0){
现在它转到res.send上一个空数组。。。
app.get('/customer/:ent_cust_id', function (req, res, next) {
    var query = 'Select * from entcustinfo where ent_cust_id = ' + req.params.ent_cust_id;
    console.log('Select * from entcustinfo where ent_cust_id =' + req.params.ent_cust_id);
    client.execute(query, function (err, result) {
    if (err) return next (err);
    var row = result.rows[0];
    //Response
    res.json({ent_cust_id: req.params.ent_cust_id, name: row.get('offers')});
});
});
[root@ip-10-205-116-141 cassapi]# /usr/local/bin/node app.js
Example app listening at http://0.0.0.0:3030
Select * from entcustinfo where ent_cust_id =1106667844
events.js:87
      throw er; // Unhandled 'error' event
            ^
TypeError: Cannot read property 'get' of undefined
    at /home/ec2-user/cassapi/app.js:16:14
    at readCallback (/home/ec2-user/cassapi/node_modules/cassandra-driver/lib/request-handler.js:195:5)
    at Connection.invokeCallback (/home/ec2-user/cassapi/node_modules/cassandra-driver/lib/connection.js:567:5)
    at Connection.handleResult (/home/ec2-user/cassapi/node_modules/cassandra-driver/lib/connection.js:507:8)
    at ResultEmitter.emit (events.js:120:17)
    at ResultEmitter.each (/home/ec2-user/cassapi/node_modules/cassandra-driver/lib/streams.js:437:17)
    at ResultEmitter._write (/home/ec2-user/cassapi/node_modules/cassandra-driver/lib/streams.js:421:10)
    at doWrite (_stream_writable.js:303:12)
    at writeOrBuffer (_stream_writable.js:290:5)
    at ResultEmitter.Writable.write (_stream_writable.js:219:11)
app.get('/customer/:ent_cust_id', function (req, res, next) {
        var query = 'Select * from entcustinfo where ent_cust_id = ' + req.params.ent_cust_id;
        console.log('Select * from entcustinfo where ent_cust_id =' + req.params.ent_cust_id);
        client.execute(query, function (err, result) {
        if (err) return next (err);
        var row = result.rows[0];
            if (row.get('ent_cust_id') = '') {
                res.send('ent_cust_id: ' + req.params.ent_cust_id + ' not found. Not all data is loaded.');
        } else {
            var row = result.rows[0];
                //Response
                res.json({ent_cust_id: req.params.ent_cust_id, accts: row.get('accts'), offers: row.get('offers')});
        }
        });
 });
TypeError: Cannot read property 'get' of undefined
/home/ec2-user/cassapi/app.js:16:14
app.get('/customer/:ent_cust_id', ...)
// or
row.get('offers')