Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-31-2019 06:39 AM
I have already written code in the nodejs which uses SQL as a database, now I want to use neo4j as a database.
So I am trying to convert the sql INSERT query to CREATE query in the neo4j, but it shows the error so please help.
Code in the SQL:
let userData = req.body;
connection.query(`INSERT INTO register (name,fname,voterid,gender,address,pincode,city,state,pic,dob,password) VALUES ('${userData.name}','${userData.fatherName}','${userData.voterId}','${userData.gender}','${userData.address}','${userData.pincode}','${userData.city}','${userData.state}','${file.originalname}','${userData.dob}','${md5(userData.password)}')`,(err,res0)=>{
if(err){
console.log(err);
res.send({
swal : {
type : "error",
text : "registration failed"
}
})
}else{
res.send({
swal : {
type : "success",
text : "registration successful"
}
})
}
Code in the neo4j:
const express = require('express');
const router = express.Router();
const neo4j = require('neo4j-driver').v1;
const md5 = require('md5');
const multer = require('multer');
const driver = neo4j.driver('bolt://localhost:7687', neo4j.auth.basic(neo4j, neo4j));
const session = driver.session();
session.run(` CREATE (n:voters { id: '${userData.voterId}', name: '${userData.name}', fname: '${userData.fatherName}', gender: '${userData.gender}', address: '${userData.address}', pincode:'${userData.pincode}', city:'${userData.city}', state:'${userData.state}', pic:'${file.originalname}', dob:'${userData.dob}',password:'${md5(userData.password)}')
)`,(err,res0)=>{
if(err){
console.log(err);
res.send({
swal : {
type : "error",
text : "registration failed"
}
})
}else{
res.send({
swal : {
type : "success",
text : "registration successful"
}
})
}
})
10-31-2019 07:00 AM
Hello and welcome to the community!
First of all, it looks like you may have a syntax problem in the Cypher query. Did you try running it in Neo4j Browser to see if it executes correctly?
Elaine
10-31-2019 07:19 AM
I tried to run but it is not running showing the error
But the error is shown only after hitting the submit button from the form, whose values I want to store
Error in the console is:
TypeError: Query parameters are expected to either be undefined/null or an object, given: Function (err,res0)=>{
if(err){
console.log(err);
res.send({
swal : {
type : "error",
text : "registration failed"
}
})
}else{
res.send({
swal : {
type : "success",
text : "registration successful"
}
})
}
}
at assertQueryParameters (C:\Users\NISHU\Angular\voters - Copy\backend\node_modules\neo4j-driver\lib\v1\internal\util.js:150:11)
at validateStatementAndParameters (C:\Users\NISHU\Angular\voters - Copy\backend\node_modules\neo4j-driver\lib\v1\internal\util.js:86:3)
at Session.run (C:\Users\NISHU\Angular\voters - Copy\backend\node_modules\neo4j-driver\lib\v1\session.js:125:76)
at router.post (C:\Users\NISHU\Angular\voters - Copy\backend\services.js:40:17)
at Layer.handle [as handle_request] (C:\Users\NISHU\Angular\voters - Copy\backend\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\NISHU\Angular\voters - Copy\backend\node_modules\express\lib\router\route.js:137:13)
at Immediate. (C:\Users\NISHU\Angular\voters - Copy\backend\node_modules\multer\lib\make-middleware.js:53:37)
at runCallback (timers.js:706:11)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
I want to write the query in the neo4j with the same functionality as it was in the sql.
10-31-2019 08:01 AM
To test the Cypher in Neo4j Browser you would modify the query to use the $userData parameter, for example:
CREATE (n:voters { id: $userData.voterId,
where the parameter userData has been set prior to running the query, for example:
:param "userData": {voterId: 'xxx', name: "yyy"}
Elaine
10-31-2019 10:50 AM
Now I have written query in the following format:
let userData = req.body;
connection.query(`INSERT INTO register (name,fname,voterid,gender,address,pincode,city,state,pic,dob,password) VALUES ('${userData.name}','${userData.fatherName}','${userData.voterId}','${userData.gender}','${userData.address}','${userData.pincode}','${userData.city}','${userData.state}','${file.originalname}','${userData.dob}','${md5(userData.password)}')`,(err,res0)=>{
if(err){
console.log(err);
res.send({
swal : {
type : "error",
text : "registration failed"
}
})
But now also after pressing the submit button it is giving the following error:
TypeError: Transaction config expected to be an object but was: undefined
at Object.assertObject (C:\Users\NISHU\Angular\voters - Copy\backend\node_modules\neo4j-driver\lib\v1\internal\util.js:95:11)
at assertValidConfig (C:\Users\NISHU\Angular\voters - Copy\backend\node_modules\neo4j-driver\lib\v1\internal\tx-config.js:132:10)
at new TxConfig (C:\Users\NISHU\Angular\voters - Copy\backend\node_modules\neo4j-driver\lib\v1\internal\tx-config.js:56:5)
at Session.run (C:\Users\NISHU\Angular\voters - Copy\backend\node_modules\neo4j-driver\lib\v1\session.js:129:52)
at router.post (C:\Users\NISHU\Angular\voters - Copy\backend\services.js:40:17)
at Layer.handle [as handle_request] (C:\Users\NISHU\Angular\voters - Copy\backend\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\NISHU\Angular\voters - Copy\backend\node_modules\express\lib\router\route.js:137:13)
at Immediate. (C:\Users\NISHU\Angular\voters - Copy\backend\node_modules\multer\lib\make-middleware.js:53:37)
at runCallback (timers.js:706:11)
at tryOnImmediate (timers.js:676:5)
Please HELP!
All the sessions of the conference are now available online