我正在使用neo4j javascript驱动程序。我能够运行一个查询。但是我无法创建具有属性的多个节点。谁能告诉我该怎么做?
session
.run('CREATE (fit1:fitproto {title:"Relaince Industries",name:"Rajni",country:"India",email:"rajni@gmail.com"}),(fit2:fitproto {title:"State Bank of India",name:"Rajni",country:"India",email:"rajni@gmail.com"}) RETURN(fitproto)')
.subscribe({
onNext: function (record) {
const node = record.get(1);
console.log(node);
record.forEach(function (res) {
console.log(res.Node);
});
res.send(record.get(0));
},
onCompleted: function () {
session.close();
},
onError: function (error) {
console.log(error);
}
});
答案 0 :(得分:2)
您需要通过参数为新节点传递属性数组。 Then UNWIND
it, create a node and SET
properties:
session
.run(`
UNWIND $propsArray as props
CREATE (fit:fitproto) SET fit = props
RETURN fit
`, {
propsArray: [{
title: "Relaince Industries",
name: "Rajni",
country: "India",
email: "rajni@gmail.com"
},
{
title: "State Bank of India",
name: "Rajni",
country: "India",
email: "rajni@gmail.com"
}
]
})
.subscribe({
onNext: function(record) {
console.log(record.get('fit'));
},
onCompleted: function() {
session.close();
},
onError: function(error) {
console.log(error);
}
});