JS 功能对象构造函数 - Neo4j 数据库没有方法 'query'
JS functional object constructor - Neo4j Database has no method 'query'
我正在使用 node-neo4j 库以及 node.js、下划线和原型。
我正在尝试拥有一个扩展数据库适配器的模型。先上代码。
BaseModel.js:
var _ = require("underscore"),
Neo4jAdapter = require('../adapters/neo4j/Adapter');
function BaseModel() {
_.extend(this, new Neo4jAdapter());
};
module.exports = BaseModel;
Neo4jAdapter.js:
var _ = require("underscore"),
Neo4j = require('neo4j');
function Neo4jAdapter() {
this.db = new Neo4j.GraphDatabase('http://localhost:3000');
};
Neo4jAdapter.prototype.insert = function(label, data, callback) {
console.log('Neo4jAdapter', 'Attempt to insert node');
if (label == '') throw 'Label is not defined';
var query = [
'CREATE (n:LABEL {mdata})',
'RETURN n'
].join('\n').replace('LABEL', label);
this.db.query(query, data, function (err, results) {
if (err) throw err;
console.log(results);
var result = results[0].n._data.data;
result.id = results[0].n._data.metadata.id;
callback(result);
});
};
module.exports = Neo4jAdapter;
奇怪的是我收到的错误。我不会在此处 post 所有 node.js / express 代码,但我会使用 url 插入插入函数。我得到的回复如下:
Message: Object #
GraphDatabase has no method 'query'
Error: TypeError: Object #
GraphDatabase has no method 'query'
我的问题是: 为什么数据库对象没有函数 query()
,即使 docs 说它应该有一个?
可能的原因: 我打赌在调用插入方法时适配器的 db 对象还没有被填充,但是我该怎么做呢?
谢谢
您可能无意中安装了较新的 alpha 版本。
看到这个问题类似的问题:https://github.com/thingdom/node-neo4j/issues/150
Hi @Christopheraburns! Run this for me:
npm ls neo4j
I'm guessing you've installed node-neo4j v2 (we have
alpha versions in npm currently), which has breaking changes to the
API. The output of that npm ls will tell you if you have node-neo4j v1
or v2 installed (e.g. 1.1.1 vs. 2.0.0-alpha3).
You can downgrade to 1.1.1 by doing:
npm uninstall neo4j npm install neo4j@1.1.1 --save
Alternately, if
you're interested in v2 (still a WIP! but almost finished, and pretty
stable), here are some temporary links until this gets merged to
master:
API docs (WIP):
https://github.com/thingdom/node-neo4j/blob/v2/API_v2.md
Hope this helps! Feel free to re-open if this doesn't resolve things
for you.
因此,您可能需要卸载neo4j并重新安装旧版本,或者查看v2中的cypher
方法。
https://github.com/thingdom/node-neo4j/blob/v2/API_v2.md#cypher
我正在使用 node-neo4j 库以及 node.js、下划线和原型。
我正在尝试拥有一个扩展数据库适配器的模型。先上代码。
BaseModel.js:
var _ = require("underscore"),
Neo4jAdapter = require('../adapters/neo4j/Adapter');
function BaseModel() {
_.extend(this, new Neo4jAdapter());
};
module.exports = BaseModel;
Neo4jAdapter.js:
var _ = require("underscore"),
Neo4j = require('neo4j');
function Neo4jAdapter() {
this.db = new Neo4j.GraphDatabase('http://localhost:3000');
};
Neo4jAdapter.prototype.insert = function(label, data, callback) {
console.log('Neo4jAdapter', 'Attempt to insert node');
if (label == '') throw 'Label is not defined';
var query = [
'CREATE (n:LABEL {mdata})',
'RETURN n'
].join('\n').replace('LABEL', label);
this.db.query(query, data, function (err, results) {
if (err) throw err;
console.log(results);
var result = results[0].n._data.data;
result.id = results[0].n._data.metadata.id;
callback(result);
});
};
module.exports = Neo4jAdapter;
奇怪的是我收到的错误。我不会在此处 post 所有 node.js / express 代码,但我会使用 url 插入插入函数。我得到的回复如下:
Message: Object #
GraphDatabase has no method 'query'
Error: TypeError: Object #
GraphDatabase has no method 'query'
我的问题是: 为什么数据库对象没有函数 query()
,即使 docs 说它应该有一个?
可能的原因: 我打赌在调用插入方法时适配器的 db 对象还没有被填充,但是我该怎么做呢?
谢谢
您可能无意中安装了较新的 alpha 版本。
看到这个问题类似的问题:https://github.com/thingdom/node-neo4j/issues/150
Hi @Christopheraburns! Run this for me:
npm ls neo4j
I'm guessing you've installed node-neo4j v2 (we have alpha versions in npm currently), which has breaking changes to the API. The output of that npm ls will tell you if you have node-neo4j v1 or v2 installed (e.g. 1.1.1 vs. 2.0.0-alpha3).
You can downgrade to 1.1.1 by doing:
npm uninstall neo4j npm install neo4j@1.1.1 --save
Alternately, if you're interested in v2 (still a WIP! but almost finished, and pretty stable), here are some temporary links until this gets merged to master:
API docs (WIP): https://github.com/thingdom/node-neo4j/blob/v2/API_v2.md
Hope this helps! Feel free to re-open if this doesn't resolve things for you.
因此,您可能需要卸载neo4j并重新安装旧版本,或者查看v2中的cypher
方法。
https://github.com/thingdom/node-neo4j/blob/v2/API_v2.md#cypher