You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Neo4j浏览器中子图查询报错:变量TomH未定义的原因咨询

Why Variable TomH not defined Error Occurs

Hey there! Let's break down exactly why you're seeing that error when running those final two lines on their own.

The Root Cause

That TomH variable you're using in the WITH clause is only valid within the context of the full 500+ line CREATE query. Here's what's happening:

  • Buried in those hundreds of CREATE statements is a line that defines TomH as a temporary alias for the Tom Hanks node (something like CREATE (TomH:Person {name: 'Tom Hanks'})).
  • Neo4j variables are query-scoped—they only exist for the duration of the single query they're created in. Once that full CREATE script finishes running, the TomH variable gets discarded entirely.
  • When you run those final two lines alone, there's no TomH variable present in your current session context, so Neo4j throws the "not defined" error because it has no idea what you're referencing.

The Simple Fix

Since you've already created the full movie graph database with the complete tutorial script, you don't need to rely on that temporary variable anymore. Instead, directly target the Tom Hanks node using its persistent label and property:

MATCH (a:Person {name: 'Tom Hanks'})-[:ACTED_IN]->(m)<-[:DIRECTED]-(d)
RETURN a, m, d LIMIT 10;

This query finds the node by its Person label and name property (which are stored in the database permanently), so it works independently of any temporary variables from earlier queries.

A Quick Cypher Variable Reminder

Always keep in mind: Variables in Cypher are just short-term aliases for nodes or relationships during a single query. They never get saved to the database, so you can't reference them across separate queries. For follow-up queries, always use labels, properties, or relationship types to target the data you need.

内容的提问来源于stack exchange,提问作者bjarkemoensted

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:49:45