83794

How to query property value when property name is a parameter?

Typically we can query property value for something like:

Match (n:Product) where n.name="iPhone X" return n

However, in my case, I don't know which property I should match, but I only know the value, in which case the property name becomes a kind of variable. I want something like this:

Match (n:Product) where n.{name}="iPhone X" return n

or with relationship variable r:

Match (n:Product)-[{r}]->(c:Color {name:'white'})

In both cases, in my application I know some property or relationship <strong>value</strong> beforehand, without knowing specifically which property it should match against.

Is this query based on property or relationship values supported in Neo4j or spring-data-neo4j?

Answer1:

Take a look in this example:

CREATE (:Node {name : 'Bruno'})-[r:REL_TYPE]->()

Setting Neo4j Browser parameters:

:param {prop : 'name', rel_type : 'REL_TYPE'}

Then querying:

MATCH (n:Node) WHERE n[{prop}] = "Bruno" RETURN n

The result:

╒════════════════╕ │"n" │ ╞════════════════╡ │{"name":"Bruno"}│ └────────────────┘

That is: you can use the property name as a key enclosed in square brackets in the WHERE clause.

An workaround to query by dynamic relationship types can be using the type() function, this way:

MATCH (:Node)-[r]->() WHERE type(r) = {rel_type} return r

Recommend

  • Spring Web Security locks Neo4j embedded database
  • DynamicRelationshipType in Spring Data Neo4j or defining relationship types at runtime
  • Making mono cross platform support for Task/Intent
  • AWS Cognito- get user information with ID
  • Keep Sql Connection open for iterating many requests? Or close each step?
  • How to convert Neo4j Result to GraphJSON
  • How to make a user wait with Laravel
  • Where in the relevant specification is it documented that some comments in a SQL script are, in fact
  • Generating anchors with PyYAML.dump()?
  • Create registry key in 32-bit hive on x64 PC using Installshield 2012 LE - Avoid redirection
  • Configuring multiple DefaultJmslistenercontainerfactory
  • crash in __tcf_0
  • Get Currently Active User in Android
  • Cypher - matching two different possible paths and return both
  • How to split circle in to the sectors in google maps?
  • For loop with if condition on multiple R functions
  • JPA flush vs commit
  • Django model inheritance, filtering models
  • What is the purpose of TaskExecutor in spring?
  • Firefox Extension - Monitor refresh and change of tab
  • Content-Length header not returned from Pylons response
  • Android fill_parent issue
  • C# - Serializing and deserializing static member
  • How reduce the height of an mschart by breaking up the y-axis
  • How to draw moving and Running sine wave chart using JFree chart in java?
  • Why doesn't :active or :focus work on text links in webkit? (safari & chrome)
  • Sending data from AppleScript to FileMaker records
  • How to apply VCL Styles to DLL-based forms in Inno Setup?
  • PHP: When would you need the self:: keyword?
  • How to include full .NET prerequisite for Wix Burn installer
  • embed rChart in Markdown
  • Android Google Maps API OnLocationChanged only called once
  • Is it possible to post an object from jquery to bottle.py?
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • How can I use `wmic` in a Windows PE script?
  • UserPrincipal.Current returns apppool on IIS
  • Unable to use reactive element in my shiny app
  • Conditional In-Line CSS for IE and Others?