OrientDB 2.2.32中in()/out()/both()函数按文档使用无结果问题
Hey there! Let’s work through this issue step by step—I’ve dealt with similar edge traversal quirks in OrientDB 2.2.x, so let’s break down what might be going wrong and how to fix it.
Step 1: First, Confirm Your Data Actually Exists
Before troubleshooting traversal queries, let’s make sure your vertices and LINK edges are properly stored. Run these quick checks:
- Verify Country vertices exist:
SELECT FROM Country - Verify PA vertices exist:
SELECT FROM PA - Check if your
Is_InLINK edges are saved (since LINK edges are stored as properties on PA vertices, not as separate edge records like standard E-class edges):SELECT is_in FROM PA
If any of these return empty, double-check how you created the LINK. For example, if you used an UPDATE to set the link, it should look like this (replace with your actual vertex criteria):
UPDATE PA SET is_in = (SELECT FROM Country WHERE name = 'France') WHERE name = 'PA_Paris'
Step 2: Correct Queries to Fetch Connected Vertices
Since Is_In is a LINK property (not a standard E-class edge), you can’t use the TRAVERSE OUT/IN('Is_In') syntax that works for regular edges. Here’s how to get both sides of the relationship:
Get Outbound Vertices (PA → Country)
To fetch all PA vertices along with their linked Country:
SELECT *, is_in FROM PA WHERE is_in IS NOT NULL
If you just want the PA vertices that have an Is_In link:
SELECT FROM PA WHERE is_in IS NOT NULL
Get Inbound Vertices (Country ← PA)
To find all Country vertices that are referenced by any PA’s Is_In link:
SELECT FROM Country WHERE @rid IN (SELECT is_in FROM PA)
Or to get all PAs linked to a specific Country (replace #12:0 with your Country’s RID):
SELECT FROM PA WHERE is_in = #12:0
Step 3: Common Pitfalls to Watch For
- Confusing LINK properties with standard edges: Standard edges (extending
E) useOUT/INfields, but LINK edges are direct properties on vertices. TheTRAVERSEsyntax won’t work here—stick to property-based queries. - Case sensitivity: OrientDB is strict about case for class and property names. Make sure
is_in(or whatever you named the LINK property) matches exactly what you used when creating it, andCountry/PAare capitalized correctly. - RID typos: If you manually specified a RID when setting the LINK, double-check it’s the correct one (e.g.,
#12:0instead of#13:0).
Optional: Switch to Standard E-Class Edges (For Easier Traversals)
If you prefer using OrientDB’s native edge model (which simplifies traversals), you can recreate your relationship as a standard edge:
- Create the edge class:
CREATE CLASS Is_In EXTENDS E - Link PA and Country vertices:
CREATE EDGE Is_In FROM (SELECT FROM PA WHERE name = 'PA_Paris') TO (SELECT FROM Country WHERE name = 'France') - Now you can use intuitive traversal queries:
- Get all PAs linked to a Country:
TRAVERSE IN('Is_In') FROM Country - Get the Country linked to a PA:
TRAVERSE OUT('Is_In') FROM PA
- Get all PAs linked to a Country:
If you’re still getting empty results after trying these steps, share the exact queries you used to create your vertices/edges and the traversal queries you attempted—I’ll help you dig deeper!
内容的提问来源于stack exchange,提问作者Marc Segond

