Reputation: 2269
In my application I create a node based on properties supplied by the user e.g. I create a node of type Score
(the type does not change) and properties such as TeamA
, TeamB
but those are dynamic (user can type whatever they want as property). How can I retrieve dynamic properties of that node later ? Neo4j client is forcing me to create a class of type Score
with fixed properties e.g. .Return(score=> score.As<Score>().**FIXED_PROPERTY_NAME**);
but I want to pass the name of dynamic property there e.g. TeamA
, how can I achieve this ?
Upvotes: 1
Views: 799
Reputation: 181
How about this?
WITH ['p1', 'p2', 'p3', 'p4'] AS properties
MATCH(score:Score)
WHERE score.cond = "some condition"
UNWIND properties AS key
WITH COLLECT([key, score[key]]) AS pairs
RETURN apoc.map.fromPairs(pairs)
Upvotes: 1
Reputation: 1395
Rather than creating Score
class with properties TeamA and TeamB
,
Create generalized class with a dictionary as property and maintain
TeamA and TeamB
as keys.
I answered similar question in detail here.
Upvotes: 0
Reputation: 6270
Short answer is that you can't do it the way you're trying to. As you said neo4jclient is strongly typed. You can get around this by passing the response yourself into a dynamic type in the same way as this answer: Casting nodes of an unknown type
Upvotes: 0