brikteknologier / seraph-model

thin model layer for seraph/neo4j (node.js)
MIT License
111 stars 28 forks source link

Successfull connect but error on write? #74

Closed evengers closed 9 years ago

evengers commented 10 years ago

seraph-model/lib/write.js:79 return node.props[self.db.options.id] != null

jonpacker commented 10 years ago

Could you provide some more context? What's the error you're getting, what's the code you're running, etc.

evengers commented 10 years ago

running node 0.11.13

doing a save like this: var themappedfields = {tester:"thetest"}; City.save(themappedfields, function (error, text) {

etc etc.

here is the error trace: TypeError: Cannot read property 'id' of undefined at /home/evengers/Documents/projects/csv2neo/node_modules/seraph-model/lib/write.js:79:24 at Array.filter (native) at Model.compose.start (/home/evengers/Documents/projects/csv2neo/node_modules/seraph-model/lib/write.js:78:37) at Model.cypherCommit (/home/evengers/Documents/projects/csv2neo/node_modules/seraph-model/lib/write.js:240:29) at /home/evengers/Documents/projects/csv2neo/node_modules/seraph-model/lib/write.js:295:22 at fn (/home/evengers/Documents/projects/csv2neo/node_modules/seraph-model/node_modules/async/lib/async.js:517:34) at /home/evengers/Documents/projects/csv2neo/node_modules/seraph-model/node_modules/async/lib/async.js:441:34 at process._tickCallback (node.js:343:11) at Function.Module.runMain (module.js:492:11) at startup (node.js:124:16)

jonpacker commented 10 years ago

That's a hard one. Could you show me your code that initialises Seraph?

evengers commented 10 years ago

On 14 Aug 2014, at 10:46, Jon Packer notifications@github.com wrote:

That's a hard one. Could you show me your code that initialises Seraph?

— Reply to this email directly or view it on GitHub.

BTW, very useful library so thanks very much in advance ....

var db = require("seraph")("http://localhost:7474"); //console.log("this db connection happened: ",db); var model = require('seraph-model');

and then

_CODE _ function setIndicesOnFirstRun(){ db.save({ name: "Test-Man", age: 40 }, function(err, node) { if (err) throw err; console.log("Test-Man inserted."); });

var City = model(db, 'cityCountry'); City.setUniqueKey('cityCountry', true); City.save({cityCountry:"fred", tester:"thetest"}, function (error, text) {});

var Lei = model(db, 'lei'); Lei.setUniqueKey('leiID', true); var Country = model(db, 'country'); Country.setUniqueKey('countryCode', true); };

setIndicesOnFirstRun(); // uncomment on setup

_END CODE _

Notice below that the db.save works but the "City.save" does not

I have had the model save working so not sure what I am doing wrong

here is the result from code above

_run results follow _

evengers@ubuntu:~/Documents/projects/csv2neo$ node --harmony index.js Test-Man inserted. /home/evengers/Documents/projects/csv2neo/node_modules/seraph-model/lib/model.js:127 if (err) throw err; ^ Error: 500 at Request._callback (/home/evengers/Documents/projects/csv2neo/node_modules/seraph/lib/seraph.js:161:17) at Request.self.callback (/home/evengers/Documents/projects/csv2neo/node_modules/seraph/node_modules/request/request.js:123:22) at Request.EventEmitter.emit (events.js:110:17) at Request. (/home/evengers/Documents/projects/csv2neo/node_modules/seraph/node_modules/request/request.js:1047:14) at Request.EventEmitter.emit (events.js:129:20) at IncomingMessage. (/home/evengers/Documents/projects/csv2neo/node_modules/seraph/node_modules/request/request.js:998:12) at IncomingMessage.EventEmitter.emit (events.js:129:20) at _stream_readable.js:898:16 at process._tickCallback (node.js:343:11)

jonpacker commented 10 years ago

In your run results there it looks like the problem is because of the setUniqueKey call. I'll take a look into this.

evengers commented 10 years ago

Thanks

saw this warning: npm WARN engine seraph@0.9.10: wanted: {"node":"~0.10.0"} (current: {"node":"v0.11.13","npm":"1.4.9"})

so I tried dropping the node-modules, going back to node 0.10.28 and re-installing node-modules for seraph-model

that got rid of the error

/home/evengers/Documents/projects/csv2neo/node_modules/seraph-model/lib/model.js:127 if (err) throw err; ^ Error: 500 at Request._callback (/home/evengers/Documents/projects/csv2neo/node_modules/seraph/lib/seraph.js:161:17) at Request.self.callback

but I am back to this error

/home/evengers/Documents/projects/csv2neo/node_modules/seraph-model/lib/write.js:79 return node.props[self.db.options.id] != null ^ TypeError: Cannot read property 'id' of undefined at /home/evengers/Documents/projects/csv2neo/node_modules/seraph-model/lib/write.js:79:24 at Array.filter (native) at Model.compose.start (/home/evengers/Documents/projects/csv2neo/node_modules/seraph-model/lib/write.js:78:37) at Model.cypherCommit (/home/evengers/Documents/projects/csv2neo/node_modules/seraph-model/lib/write.js:240:29) at /home/evengers/Documents/projects/csv2neo/node_modules/seraph-model/lib/write.js:295:22 at fn (/home/evengers/Documents/projects/csv2neo/node_modules/seraph-model/node_modules/async/lib/async.js:517:34) at /home/evengers/Documents/projects/csv2neo/node_modules/seraph-model/node_modules/async/lib/async.js:441:34 at process._tickCallback (node.js:343:11) at Function.Module.runMain (module.js:492:11) at startup (node.js:124:16)

Here are the node_modules installed under 10.28 underscore@1.5.2 node_modules/underscore

async@0.1.22 node_modules/async

moment@2.0.0 node_modules/moment

mocha@1.21.4 node_modules/mocha ├── diff@1.0.7 ├── growl@1.8.1 ├── commander@2.0.0 ├── mkdirp@0.3.5 ├── debug@1.0.4 (ms@0.6.2) ├── jade@0.26.3 (commander@0.6.1, mkdirp@0.3.0) └── glob@3.2.3 (inherits@2.0.1, graceful-fs@2.0.3, minimatch@0.2.14)

disposable-seraph@0.3.1 node_modules/disposable-seraph ├── async@0.2.10 ├── neo4j-vm@0.1.10 (async@0.1.22) ├── randy@1.4.3 ├── neo4j-supervisor@0.1.1 (naan@1.3.11, rimraf@2.1.4) └── seraph@0.9.10 (naan@1.3.11, request@2.40.0)

On 14 Aug 2014, at 11:32, Jon Packer notifications@github.com wrote:

In your run results there it looks like the problem is because of the setUniqueKey call. I'll take a look into this.

— Reply to this email directly or view it on GitHub.

oscar-g commented 10 years ago

I was having the same Cannot read property 'id' of undefined yesterday. Turned out to be an error in my db connection; make sure you're doing var db = seraph({ server : db_url }) correctly. It seems like maybe an earlier version of seraph() isn't able to connect with out the {server: 'url' } object.

evengers commented 10 years ago

Thanks very much for the tip.

I tried various connection variations without luck. The connections are made but the seraph-model errors remain. (Perhaps because I was fiddling about with promises).

I went with the following. It works fine.

function saveTheNodeWithLabel(themappedfields,targetID,theLabels) { db.save(themappedfields, function(err, node) { if (err) logRejects ("line: " + ctr + "node save prob "); targetID = targetID + ": "+node.id ; db.label(node, theLabels, function(err) {
if (err) logRejects ("line: " + ctr + "label prob ");
//OPTIONAL db.read(node.id, function(err, node) { ev.emit('customEvent', targetID, function(){}); //OPTIONAL });//read
})//label })//db.save }; //end saveTheNodes

P.S. I do this for reading each row of a large csv file into neo after a set of nodes are created for each row I go on to build relations for the row and then continue to step through the file row by row. ... seems to work fine now.

On 14 Aug 2014, at 14:52, oscar-g notifications@github.com wrote:

I was having the same Cannot read property 'id' of undefined yesterday. Turned out to be an error in my db connection; make sure you're doing var db = seraph({ server : db_url }) correctly. It seems like maybe an earlier version of seraph() isn't able to connect with out the {server: 'url' } object.

— Reply to this email directly or view it on GitHub.