I'm trying to create an unique node in neo4j, but can't make it work.
node code:
var node = db.createNode({sampleDataKey: "sampleDataValue"});
node.save(function (err, user) {
node.index('user', 'indexValue', 'indexValue', function (err) {
if (err) console.log(err);
console.log(user.id);
});
});
I'm using this node module: https://github.com/thingdom/node-neo4j
I have modified the Node.js from the neo4j lib. to:
else {
var urlToPost = ((("" + services.node_index) + "/") + index + '?uniqueness=create_or_fail');
console.log(urlToPost);
console.log(key + ':' + value);
/* 123 */ return __this._request.post({
/* 124 */ url: urlToPost,
/* 125 */ json: {
/* 126 */ key: key,
/* 127 */ value: value,
/* 128 */ uri: __this.self
}
}, __cb(_, __frame, 17, 21, function ___(__0, __4) {
/* 123 */ response = __4;
console.log('response');
__then();
}, true));
}
Each time i execute the code a new new node is created, but after that errors. ... Here is the console log for 2 executions:
30 May 16:51:24 - [nodemon] starting `node app.js`
Express server listening on port 3000
http://localhost:7474/db/data/index/node/user?uniqueness=create_or_fail
indexValue:indexValue
response
338
30 May 16:55:38 - [nodemon] restarting due to changes...
30 May 16:55:38 - [nodemon] /Users/nikolaialeksandrenko/Documents/work/noject/app.js
30 May 16:55:38 - [nodemon] starting `node app.js`
Express server listening on port 3000
http://localhost:7474/db/data/index/node/user?uniqueness=create_or_fail
indexValue:indexValue
response
339
The problem is from the version i was using (1.8.2) the optional '?uniqueness=create_or_fail' work just fine in neo4j 1.9. The only think i have to do was to update to the newer version.