OrientDB:如何在UPDATE操作中使用MATCH语法?
Great question! Let me break this down clearly for you—you're on the right track with wanting to use a match pattern to target nodes/relationships for updates, but the syntax you're trying isn't how Cypher (Neo4j's query language) works.
First off: Neo4j doesn't use an UPDATE keyword to wrap a MATCH clause like you attempted with UPDATE (MATCH...RETURN...) SET.... Instead, the standard approach is to use MATCH directly to locate the elements you want to modify, then follow it with SET to apply your updates.
Correct Syntax Example for Node Updates
If you want to update nodes that match a specific pattern, here's how you'd write it:
MATCH (n:Customer {email: 'john@example.com'}) SET n.lastLogin = datetime(), n.status = 'active' RETURN n
- The
MATCHclause finds allCustomernodes with the matching email. - The
SETclause updates thelastLoginandstatusproperties of those nodes. - Optional: Add a
RETURNclause to verify the updated nodes.
Example for Relationship Updates
This works for relationships too—just match the relationship pattern and set its properties:
MATCH (u:User)-[r:FOLLOWS]->(p:Profile) WHERE u.username = 'jane_doe' AND p.displayName = 'Tech Insights' SET r.followedAt = datetime(), r.notificationsEnabled = true RETURN r
Why Your Original Approach Didn't Work
The UPDATE #12:34 SET... syntax you mentioned is a shorthand for updating a single node by its internal ID, but when you want to use a pattern match to target multiple elements, you don't need an UPDATE wrapper. Cypher combines the matching and updating steps directly with MATCH + SET.
So to recap: Skip the UPDATE keyword entirely, structure your query as MATCH [your pattern] [optional WHERE clause] SET [updates], and you'll get the behavior you're looking for.
内容的提问来源于stack exchange,提问作者eric

