All Products
Search
Document Center

:Data update syntax

Last Updated:Feb 21, 2024

This topic describes the data update syntax.

Syntax

You can add, update, or delete a vertex or an edge by using the Gremlin syntax. To add or update a vertex or an edge, you must specify all the properties of the vertex or edge. To delete a vertex or an edge, you need to only specify the primary key (PKey).

  • Add a vertex

Syntax:

g("The name of the specified graph").addV("The type of the specified vertex").property("pkey","The ID of the specified vertex").property("The name of the specified property","The value of the property")

Example:

g("tinkerpop").addV("person").property("pkey","11").property("name","Durant").property("age","34")

Note: The pkey property specifies the unique key of the vertex. Do not change the name of the pkey property.

  • Update a vertex

Syntax:

g("The name of the specified graph").addV("The type of the specified vertex").property("pkey","The ID of the specified vertex").property("The name of the specified property","The value of the property")

Example:

g("tinkerpop").addV("person").property("pkey","11").property("name","Durant1").property("age","345")

Note: The pkey property specifies the unique key of the vertex. Do not change the name of the pkey property.

  • Add an edge

Syntax:

g("The name of the specified graph").addE("The type of the specified edge").property(" pkey","The ID of the start vertex").property("skey","The ID of the end vertex").property("The name of the specified property","The value of the property")

Example:

g("tinkerpop").addE("relation").property("pkey","11").property("skey","11").property("name","Durant")

.property("age","34")

Note: Do not change the names of the pkey and skey properties.

  • Update an edge

Syntax:

g("The name of the specified graph").addE("the type of the specified edge").property(" pkey","The ID of the start vertex").property("skey","The ID of the end vertex").property("The name of the specified property","The value of the property")

Example:

g("tinkerpop").addE("relation").property("pkey","11").property("skey","11").property("name","Durant123")

.property("age","345")

Note: Do not change the names of the pkey and skey properties.

  • Delete a vertex

Syntax:

g("The name of the specified graph").V("The ID of the specified vertex").hasLabel("The type of the specified vertex").drop()

Example:

g("your_graph_name").V("pk_value").hasLabel("your_label").drop()

  • Delete an edge

Syntax:

g("The name of the specified graph"). E("The ID of the specified edge").hasLabel("The type of the specified edge").drop()

Example:

g("graph_name").E("pk1").haslabel("label").drop()

Usage notes

For more information, see Usage notes.