如何使用Gremlin将Node js与cassandra DSE图连接?连接不起作用

时间:2017-09-12 08:33:35

标签: node.js cassandra datastax gremlin

我尝试在使用gremlin的DSC中将节点js连接到Cassandra DB。如何连接Cassandra DB? 我正在使用 1.Node js, 2.Express js, 3. Cassandra db, 4.数据栈工作室(DSE), 5.Gramlin查询(nosql)。 我尝试了这两种方法,但无法连接。如何连接Cassandra DB,DSE和使用Gramlin Query?谢谢。



//1.I tried this one first
var dse = require('dse-driver');
var dse_driver = new dse.Client({
   contactPoints: ['127.0.0.1'],
   protocolOptions: {
     port: 9042
   },
   graphOptions: {
    name: 'Demo_work_graph'
   }
});
//2.I use this one also
var cassandra = require('cassandra-driver');
var async = require('async');
var client = new cassandra.Client({ contactPoints: ['127.0.0.1'], graphOptions: {name: 'Demo_work_graph'} });




我收到此错误



error { Error: line 1:0 no viable alternative at input 'g' ([g]...)
    at ResponseError.DriverError (/home/periyasamy/K12OS/server/node_modules/dse-driver/lib/errors.js:20:19)
    at new ResponseError (/home/periyasamy/K12OS/server/node_modules/dse-driver/lib/errors.js:57:24)
    at FrameReader.readError (/home/periyasamy/K12OS/server/node_modules/dse-driver/lib/readers.js:338:13)
    at Parser.parseBody (/home/periyasamy/K12OS/server/node_modules/dse-driver/lib/streams.js:200:66)
    at Parser._transform (/home/periyasamy/K12OS/server/node_modules/dse-driver/lib/streams.js:143:10)
    at Parser.Transform._read (_stream_transform.js:186:10)
    at Parser.Transform._write (_stream_transform.js:174:12)
    at doWrite (_stream_writable.js:385:12)
    at writeOrBuffer (_stream_writable.js:371:5)
    at Parser.Writable.write (_stream_writable.js:288:11)
  name: 'ResponseError',
  stack: 'Error: line 1:0 no viable alternative at input \'g\' ([g]...)\n    at ResponseError.DriverError (/home/periyasamy/K12OS/server/node_modules/dse-driver/lib/errors.js:20:19)\n    at new ResponseError (/home/periyasamy/K12OS/server/node_modules/dse-driver/lib/errors.js:57:24)\n    at FrameReader.readError (/home/periyasamy/K12OS/server/node_modules/dse-driver/lib/readers.js:338:13)\n    at Parser.parseBody (/home/periyasamy/K12OS/server/node_modules/dse-driver/lib/streams.js:200:66)\n    at Parser._transform (/home/periyasamy/K12OS/server/node_modules/dse-driver/lib/streams.js:143:10)\n    at Parser.Transform._read (_stream_transform.js:186:10)\n    at Parser.Transform._write (_stream_transform.js:174:12)\n    at doWrite (_stream_writable.js:385:12)\n    at writeOrBuffer (_stream_writable.js:371:5)\n    at Parser.Writable.write (_stream_writable.js:288:11)',
  message: 'line 1:0 no viable alternative at input \'g\' ([g]...)',
  info: 'Represents an error message from the server',
  code: 8192,
  coordinator: '127.0.0.1:9042',
  query: 'g.V()' }




1 个答案:

答案 0 :(得分:0)

您应该使用dse-driver

const client = new dse.Client({ 
  contactPoints: ['host1'], 
  graphOptions: {
    name: 'Demo_work_graph'
  }
});

client.executeGraph('g.V().count()')
  .then(console.log)
  .catch(console.error);