diff --git a/docs-2.0/2.quick-start/6.cheatsheet-for-ngql.md b/docs-2.0/2.quick-start/6.cheatsheet-for-ngql.md index 282d6bc93b6..d3dbbe73495 100644 --- a/docs-2.0/2.quick-start/6.cheatsheet-for-ngql.md +++ b/docs-2.0/2.quick-start/6.cheatsheet-for-ngql.md @@ -185,14 +185,14 @@ | Match vertices | `(v)` | You can use a user-defined variable in a pair of parentheses to represent a vertex in a pattern. For example: `(v)`. | | Match tags | `MATCH (v:player) RETURN v` | You can specify a tag with `:` after the vertex in a pattern. | | Match multiple tags | `MATCH (v:player:team) RETURN v LIMIT 10` | To match vertices with multiple tags, use colons (:). | - | Match vertex properties | `MATCH (v:player{name:"Tim Duncan"}) RETURN v` | You can specify a vertex property with `{: }` after the tag in a pattern. | + | Match vertex properties | `MATCH (v:player{name:"Tim Duncan"}) RETURN v`

`MATCH (v) WITH v, properties(v) as props, keys(properties(v)) as kk LIMIT 10000 WHERE [i in kk where props[i] == "Tim Duncan"] RETURN v` | You can specify a vertex property with `{: }` after the tag in a pattern; or use a vertex property value to get vertices directly. | | Match a VID. | `MATCH (v) WHERE id(v) == 'player101' RETURN v` | You can use the VID to match a vertex. The `id()` function can retrieve the VID of a vertex. | | Match multiple VIDs. | `MATCH (v:player { name: 'Tim Duncan' })--(v2) WHERE id(v2) IN ["player101", "player102"] RETURN v2` | To match multiple VIDs, use `WHERE id(v) IN [vid_list]`. | | Match connected vertices | `MATCH (v:player{name:"Tim Duncan"})--(v2) RETURN v2.player.name AS Name` | You can use the `--` symbol to represent edges of both directions and match vertices connected by these edges. You can add a `>` or `<` to the `--` symbol to specify the direction of an edge. | | Match paths | `MATCH p=(v:player{name:"Tim Duncan"})-->(v2) RETURN p` | Connected vertices and edges form a path. You can use a user-defined variable to name a path as follows. | | Match edges | `MATCH (v:player{name:"Tim Duncan"})-[e]-(v2) RETURN e`
`MATCH ()<-[e]-() RETURN e LIMIT 3` | Besides using `--`, `-->`, or `<--` to indicate a nameless edge, you can use a user-defined variable in a pair of square brackets to represent a named edge. For example: `-[e]-`. | | Match an edge type | `MATCH ()-[e:follow]-() RETURN e LIMIT 5` |Just like vertices, you can specify an edge type with `:` in a pattern. For example: `-[e:follow]-`. | - | Match edge type properties | ` MATCH (v:player{name:"Tim Duncan"})-[e:follow{degree:95}]->(v2) RETURN e` | You can specify edge type properties with `{: }` in a pattern. For example: `[e:follow{likeness:95}]`. | + | Match edge type properties | ` MATCH (v:player{name:"Tim Duncan"})-[e:follow{degree:95}]->(v2) RETURN e`

`MATCH ()-[e]->() WITH e, properties(e) as props, keys(properties(e)) as kk LIMIT 10000 WHERE [i in kk where props[i] == 90] RETURN e`| You can specify edge type properties with `{: }` in a pattern. For example: `[e:follow{likeness:95}]`; or use an edge type property value to get edges directly. | | Match multiple edge types | `MATCH (v:player{name:"Tim Duncan"})-[e:follow | :serve]->(v2) RETURN e` | The `|` symbol can help matching multiple edge types. For example: `[e:follow|:serve]`. The English colon (:) before the first edge type cannot be omitted, but the English colon before the subsequent edge type can be omitted, such as `[e:follow|serve]`. | | Match multiple edges | `MATCH (v:player{name:"Tim Duncan"})-[]->(v2)<-[e:serve]-(v3) RETURN v2, v3` | You can extend a pattern to match multiple edges in a path. | | Match fixed-length paths | `MATCH p=(v:player{name:"Tim Duncan"})-[e:follow*2]->(v2) RETURN DISTINCT v2 AS Friends` | You can use the `:*` pattern to match a fixed-length path. `hop` must be a non-negative integer. The data type of `e` is the list.| diff --git a/docs-2.0/3.ngql-guide/7.general-query-statements/2.match.md b/docs-2.0/3.ngql-guide/7.general-query-statements/2.match.md index 57ecaf5f21c..6c574dbc037 100644 --- a/docs-2.0/3.ngql-guide/7.general-query-statements/2.match.md +++ b/docs-2.0/3.ngql-guide/7.general-query-statements/2.match.md @@ -195,6 +195,21 @@ nebula> MATCH (v:player) \ In openCypher 9, `=` is the equality operator. However, in nGQL, `==` is the equality operator and `=` is the assignment operator (as in C++ or Java). + +You also use properties without specifying a tag to get vertices directly. For example, to get all the vertices with the vertex property value Tim Duncan. + +```ngql +nebula> MATCH (v) \ + WITH v, properties(v) as props, keys(properties(v)) as kk \ + LIMIT 10000 WHERE [i in kk where props[i] == "Tim Duncan"] \ + RETURN v; ++----------------------------------------------------+ +| v | ++----------------------------------------------------+ +| ("player100" :player{age: 42, name: "Tim Duncan"}) | ++----------------------------------------------------+ +``` + ### Match VIDs You can use the VID to match a vertex. The `id()` function can retrieve the VID of a vertex. @@ -399,6 +414,25 @@ nebula> MATCH (v:player{name:"Tim Duncan"})-[e:follow{degree:95}]->(v2) \ +--------------------------------------------------------+ ``` + +You also use properties without specifying an edge type to get edges directly. For example, to get all the edges with the edge property value 90. + +```ngql +nebula> MATCH ()-[e]->() \ + WITH e, properties(e) as props, keys(properties(e)) as kk \ + LIMIT 10000 WHERE [i in kk where props[i] == 90] \ + RETURN e; ++----------------------------------------------------+ +| e | ++----------------------------------------------------+ +| [:follow "player125"->"player100" @0 {degree: 90}] | +| [:follow "player140"->"player114" @0 {degree: 90}] | +| [:follow "player133"->"player144" @0 {degree: 90}] | +| [:follow "player133"->"player114" @0 {degree: 90}] | +... ++----------------------------------------------------+ +``` + ### Match multiple edge types The `|` symbol can help matching multiple edge types. For example: `[e:follow|:serve]`. The English colon (:) before the first edge type cannot be omitted, but the English colon before the subsequent edge type can be omitted, such as `[e:follow|serve]`.