neo4j - 如何连接 Nest.js 和 NEO4j
问题描述
我是 Neo4j 的新手,希望它与 Nest.js 连接,我正在使用 Neo4j 版本 3.5.12 并按照教程进行操作。我使用 Graphql 连接 Nest.js 和 Neo4j,但我们无法获得结果并显示一些 JSON 类型和我也尝试不使用 Graphql,但 GET 和 POST 不起作用。
这是我的控制器
import { Controller, Get } from '@nestjs/common';
import {Neo4jService} from './neo4j.service';
@Controller('neo4j')
export class Neo4jController {
constructor (private readonly retriveNodes: Neo4jService){}
@Get()
async findAll() {
console.log('retriving nodes as per given query in findAll() method. ');
//return'Welcome To All';
return this.retriveNodes.findAll();
}
}
服务
import { Injectable, Inject } from '@nestjs/common';
import * as v1 from 'neo4j-driver';
@Injectable()
export class Neo4jService {
constructor(@Inject("Neo4j") private readonly neo4j: v1.Driver) {}
async findAll(): Promise<any> {
return this.neo4j.session().run('MATCH (n:Movie) RETURN n LIMIT 5');
}
}
使用它,我得到 JSON 格式的结果。
输出
{
"records": [
{
"keys": [
"n"
],
"length": 1,
"_fields": [
{
"identity": {
"low": 0,
"high": 0
},
"labels": [
"Movie"
],
"properties": {
"title": "The Martix",
"year": {
"low": 1999,
"high": 0
},
"id": "82999192-ae57-406e-8c19-d7753d0d5748"
}
}
],
"_fieldLookup": {
"n": 0
}
},
{
"keys": [
"n"
],
"length": 1,
"_fields": [
{
"identity": {
"low": 1,
"high": 0
},
"labels": [
"Movie"
],
"properties": {
"title": "A Few Good Men",
"year": {
"low": 1992,
"high": 0
},
"id": "c52c721c-c410-45a2-8d2e-824caa51847a"
}
}
],
"_fieldLookup": {
"n": 0
}
},
{
"keys": [
"n"
],
"length": 1,
"_fields": [
{
"identity": {
"low": 2,
"high": 0
},
"labels": [
"Movie"
],
"properties": {
"title": "Top Gun",
"year": {
"low": 1986,
"high": 0
},
"id": "d121663a-597f-4963-8acc-c68021bee860"
}
}
],
"_fieldLookup": {
"n": 0
}
},
{
"keys": [
"n"
],
"length": 1,
"_fields": [
{
"identity": {
"low": 17,
"high": 0
},
"labels": [
"Movie"
],
"properties": {
"title": "The Martix",
"year": {
"low": 1999,
"high": 0
},
"id": "453941ca-c309-419b-8cad-41d150e06b2a"
}
}
],
"_fieldLookup": {
"n": 0
}
},
{
"keys": [
"n"
],
"length": 1,
"_fields": [
{
"identity": {
"low": 18,
"high": 0
},
"labels": [
"Movie"
],
"properties": {
"title": "A Few Good Men",
"year": {
"low": 1992,
"high": 0
},
"id": "79fc529c-bfd1-4f7d-9bae-7f00b6d7d540"
}
}
],
"_fieldLookup": {
"n": 0
}
}
],
"summary": {
"query": {
"text": "MATCH (n:Movie) RETURN n LIMIT 5",
"parameters": {
}
},
"queryType": "r",
"counters": {
"_stats": {
"nodesCreated": 0,
"nodesDeleted": 0,
"relationshipsCreated": 0,
"relationshipsDeleted": 0,
"propertiesSet": 0,
"labelsAdded": 0,
"labelsRemoved": 0,
"indexesAdded": 0,
"indexesRemoved": 0,
"constraintsAdded": 0,
"constraintsRemoved": 0
},
"_systemUpdates": 0
},
"updateStatistics": {
"_stats": {
"nodesCreated": 0,
"nodesDeleted": 0,
"relationshipsCreated": 0,
"relationshipsDeleted": 0,
"propertiesSet": 0,
"labelsAdded": 0,
"labelsRemoved": 0,
"indexesAdded": 0,
"indexesRemoved": 0,
"constraintsAdded": 0,
"constraintsRemoved": 0
},
"_systemUpdates": 0
},
"plan": false,
"profile": false,
"notifications": [
],
"server": {
"address": "localhost:7687",
"version": "Neo4j/3.5.12"
},
"resultConsumedAfter": {
"low": 191,
"high": 0
},
"resultAvailableAfter": {
"low": 437,
"high": 0
},
"database": {
"name": null
}
}
}
我想要 .run 和 .then 但在这里只有 .run 显示。没有 sugection 显示我想要上面代码中的字段、属性和 id。
解决方案
推荐阅读
- python - 在另一个 Python 脚本中使用输出 .csv 文件
- javascript - Bootstrap 音频播放器的列布局
- spring-boot - SonarCloud 在 Springboot 的 contextLoads 单元测试中引发“阻止程序”
- python - 在Django中与模型返回一对一的模型信息
- python - 根据列中的值在熊猫中创建两个数据框
- javascript - 我可以在 PyQt5 QWebEngine 中将 Python 连接到 JavaScript 吗?
- python - 进行多项式线性回归时,Matplotlib 上的 x 轴不正确
- php - 当视图具有 @can 指令时,模拟 Laravel Gate 失败
- c - 如何将关系运算符与随机数生成器一起使用 (c)
- python - 有没有办法将 OneHot 编码的 SciPy 稀疏矩阵应用于 PCA?