Javascript中的Neo4j:参数未输入查询

时间:2014-11-26 01:44:28

标签: javascript node.js neo4j cypher

使用neo4j plugin of thingdom时遇到了麻烦。看起来该插件无法将 {mlabel} {mdata} 识别为占位符。代码和错误如下。

非常感谢!

var query = [
    'CREATE (p:{mlabel} {{mdata}})',
    'RETURN p'
].join('\n');

var params = {
    mlabel : 'person',
    mdata  : {
        name: 'Pete',
        surname: 'Strutton',
        age: 35
    }
};

this.db.query(query, params, function (err, results) {
    if (err) throw err;
    return result;
});
Error: Invalid input '{': expected whitespace or a label name (line 1, column 11)
"CREATE (p:{mlabel} {{mdata}})"
           ^
    at exports.adjustError (C:\Spree Github Repository\Phone\express\SpreeRouter
\node_modules\neo4j\lib\util.js:71:15)
    at __$GraphDatabase_prototype_query__20 (C:\Spree Github Repository\Phone\ex
press\SpreeRouter\node_modules\neo4j\lib\GraphDatabase.js:942:26)
    at C:\Spree Github Repository\Phone\express\SpreeRouter\node_modules\neo4j\l
ib\GraphDatabase.js:2:6247
    at Object.__g.trampoline.flush (C:\Spree Github Repository\Phone\express\Spr
eeRouter\node_modules\neo4j\lib\Node.js:2:3552)
    at Request.___ [as _callback] (C:\Spree Github Repository\Phone\express\Spre
eRouter\node_modules\neo4j\lib\GraphDatabase.js:2:5602)
    at Request.self.callback (C:\Spree Github Repository\Phone\express\SpreeRout
er\node_modules\neo4j\node_modules\request\request.js:372:22)
    at Request.emit (events.js:98:17)
    at Request.<anonymous> (C:\Spree Github Repository\Phone\express\SpreeRouter
\node_modules\neo4j\node_modules\request\request.js:1317:14)
    at Request.emit (events.js:117:20)
    at IncomingMessage.<anonymous> (C:\Spree Github Repository\Phone\express\Spr
eeRouter\node_modules\neo4j\node_modules\request\request.js:1265:12)

1 个答案:

答案 0 :(得分:2)

解决方案:

您无法在任何地方参数化查询选择器。只有您在查询中输入的数据才有可能。以上内容不起作用,但以下查询将:

var query = [
    'CREATE (p:LABEL {mdata})',
    'RETURN p'
].join('\n').replace('LABEL', label);

var params = {
    mdata  : data
};

this.db.query(query, params, function (err, results) {
    if (err) throw err;
    console.log(results);
    return results[0];
});