I have a problem while creating a node using the V2 package. I end up getting a Cannot read property '0' of undefined error. I realize that the callback is trying to read results[0] which is likely causing this problem. however my cypher query should return result(s) right?
var neo4j = require('neo4j');
db.cypher({
query: 'Create (user:User {username: {username}, email: {email}, password: {password},dateofbirth: {dateofbirth}, ismale: {ismale}, firstname: {firstname}, lastname: {lastname}}) return user',
params: {
username: username,
email: email,
password: password,
dateofbirth : dateofbirth,
ismale : gender,
firstname: firstname,
lastname: lastname,
},
}, callback);
function callback(err, results) {
if (err) reply({ Error: err });
var result = results[0];
if (!result) {
reply("Cannot Create User");
} else {
var user = result['user'];
reply(user);
}
};
I get this error
Debug: internal, implementation, error
TypeError: Uncaught error: Cannot read property '0' of undefined
at callback (C:\Project\server.js:152:33)
at C:\Project\node_modules\neo4j\lib-new\GraphDatabase.js:301:18
at Request._callback (C:\Project\node_modules\neo4j\lib-new\GraphDatabase.js:92:20)
at Request.init.self.callback (C:\Project\node_modules\neo4j\node_modules\request\request.js:198:22)
at Request.emit (events.js:110:17)
at Request.<anonymous> (C:\Project\node_modules\neo4j\node_modules\request\request.js:1082:10)
at Request.emit (events.js:129:20)
at IncomingMessage.<anonymous> (C:\Project\node_modules\neo4j\node_modules\request\request.js:1009:12)
at IncomingMessage.emit (events.js:129:20)
at _stream_readable.js:908:16
This only happens when i attempt to create a node on neo4j. When I replace the query with a match query it seems to work fine. What am i doing wrong?