Neo4j in Azure mobile services

2020-07-30 03:44发布

问题:

I have been trying to use a Neo4j database as my database in an Azure Mobile service. I was following this tutorial and I cant seem to get it to work. Basically what the tutorial does is:

  • Creates a VM hosted by Azure, running ubuntu and neo4j.
  • Creates an Azure mobile service with an SQL table.
  • Writes an insert script for the SQL table that uses node.js to connect to the Neo4j VM and past the data there.

Unfortunately mine does not seem to work. The data gets posted to the mobile services SQL table but the script to post to the Neo4j server on the VM does not seem to work. I also know that the VM is setup correctly because I can connect to it in the Neo4j web admin page.

Here is the code for the script:

    function insert(item, user, request) {
    //comment to trigger .js creation
    var neo4j = require('neo4j');
    var db = new neo4j.GraphDatabase('http://<username>:<password>@http://neo4jmobile.cloudapp.net:7474');
    var node = db.createNode({ name: item.name });
    node.save(function (err, node) {
        if (err) {
            console.error('Error saving new node to database:', err);
        }
        else {
            console.log('Node saved to database with id:', node.id);
        }
    });

    request.execute();

}

Does any one have any experience with this? Is there something wrong with my script? With the tutorials approach? Any help would be appreciated.

EDIT: There was a problem with the line: console.err('Error saving new node to database:', err); which had to be replace with console.err('Error saving new node to database:', err);. However I am now getting this error message:

Error saving new node to database: { [Error: connect ETIMEDOUT]
  stack: [Getter/Setter],
  code: 'ETIMEDOUT',
  errno: 'ETIMEDOUT',
  syscall: 'connect',
  __frame:
   { name: 'GraphDatabase_prototype__getRoot__1',
     line: 76,
     file: '\\\\10.211.156.195\\volume-0-default\\bf02c8bd8f7589d46ba1\\4906fa4587734dd087df8e641513f602\\site\\wwwroot\\App_Data\\config\\scripts\\node_modules\\neo4j\\lib\\GraphDatabase.js',
     prev:
      { name: 'GraphDatabase_prototype_getServices__2',
        line: 99,
        file: '\\\\10.211.156.195\\volume-0-default\\bf02c8bd8f7589d46ba1\\4906fa4587734dd087df8e641513f602\\site\\wwwroot\\App_Data\\config\\scripts\\node_modules\\neo4j\\lib\\GraphDatabase.js',
        prev: [Object],
        active: false,
        offset: 5,
        col: 12 },
     active: false,
     offset: 5,
     col: 12 },
  rawStack: [Getter] }

Once again, any help would be appreciated!

回答1:

Did you enable source control and npm install the neo4j module?

Miranda



回答2:

Ok I managed to figure it out. The problem was that the tutorial (and documentation for neo4j for node.js) had a typo. The code should have been console.error() rather than console.err().