Cannot read property '0' of undefined

36 views
Skip to first unread message

Xavier Thomas

unread,
Oct 26, 2015, 9:37:29 AM10/26/15
to Node-Neo4j
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?

Aseem Kishore

unread,
Oct 26, 2015, 9:40:51 AM10/26/15
to Xavier Thomas, Node-Neo4j
however my cypher query should return result(s) right?

Yes — unless there's an error! And I notice you're not properly returning/exiting the callback in the case of an error. So that's very likely it. =)

Aseem

Xavier Thomas

unread,
Oct 27, 2015, 2:11:19 AM10/27/15
to Node-Neo4j, xav...@gmail.com
I thought I would try something with Hapi but I guess its not working as intended.
I replaced it with a throw err and handled it with try catch and I seem to be working now.
Thanks for your help :)
Reply all
Reply to author
Forward
0 new messages