我的代码!!
var neo4j = require('neo4j-driver').v1;
var express = require('express');
var logger = require('morgan');
var path = require('path');
var bodyParser =require('body-parser');
var app=express();
app.set('views',path.join(__dirname, 'views'));
app.set('view engine','ejs');
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(express.static(path.join(__dirname,'public')));
var driver = neo4j.driver("bolt://localhost:7687", neo4j.auth.basic("Novasys", "123456"));
var session = driver.session();
app.get('/', function(req,res){
session
.run('MATCH (n:Movie) RETURN n LIMIT 30')
.then(function(result){
var moviearr = [];
result.records.forEach(function(record){
moviearr.push({enter code here
id: record._fields[0].identity.low,
title: record._fields[0].properties.title,
released: record._fields[0].properties.released
});
});
session
.run('MATCH (n:Person) RETURN n LIMIT 25')
.then(function(result2){
var personArr = [];
result2.records.forEach(function(record){
personArr.push({
id: record._fields[0].identity.low,
name: record._fields[0].properties.name
});
});
res.render('index', {
movies: moviearr,
persons: personArr
});
})
.catch(function(err){
console.log(err);
});
})
.catch(function(err){
console.log(err);
});
});
app.post('/movie/add',function(req,res,next){
var title = req.body.title;
var released = req.body.released;
session
.run('CREATE(n:Movie {title:{titleParam}, released:{releasedParam}}) RETURN n.title',{titleParam:title, releasedParam:released})
.then(function(result){
res.redirect();
session.close();
})
.catch(function(err){
console.log(err);
});
res.redirect('/');
});
app.listen(4000);
console.log('Server started on port 4000');
module.exports=app; **strong text**
得到错误!!
TypeError:无法读取未定义的属性“name” 在B:\ nodejs \ newp \ app.js:75:30 在Layer.handle [as handle_request](B:\ nodejs \ newp \ node_modules \ express \ lib \ router \ layer.js:95:5) 在下一个(B:\ nodejs \ newp \ node_modules \ express \ lib \ router \ route.js:131:13) 在Route.dispatch(B:\ nodejs \ newp \ node_modules \ express \ lib \ router \ route.js:112:3) 在Layer.handle [as handle_request](B:\ nodejs \ newp \ node_modules \ express \ lib \ router \ layer.js:95:5) 在B:\ nodejs \ newp \ node_modules \ express \ lib \ router \ index.js:277:22 在Function.process_params(B:\ nodejs \ newp \ node_modules \ express \ lib \ router \ index.js:330:12) 在下一个(B:\ nodejs \ newp \ node_modules \ express \ lib \ router \ index.js:271:10) 在serveStatic(B:\ nodejs \ newp \ node_modules \ serve-static \ index.js:75:16) 在Layer.handle [as handle_request](B:\ nodejs \ newp \ node_modules \ express \ lib \ router \ layer.js:95:5)
任何人都可以帮我解决这个问题。我是节点js以及neo4j的新手。
先谢谢
答案 0 :(得分:1)
☼你好,
您的Neo4j数据库中是否有“人物”标签?
session
.run('MATCH (n:Person) RETURN n LIMIT 25')
您是否尝试过:
session
.run('MATCH (n:Actor) RETURN n LIMIT 25')
我认为你采用了这个例子here,但他们使用标签“电影”和“演员”