AT
Apache TinkerPopamandeep1520

Adding multiple properties to a vertex using gremlin-go

Hello Community, I have a question regarding how multiple properties can be added to a vertex using gremlin-go. I did something like this prop := map[string]interface{}{ "name": "Daniel", "age": "37", } g.GetTraversal().Inject(prop).Unfold().As("M").AddV("Person").As("V").Select("M").Unfold().As("KV").Select("V").Property( g.GetTraversal().V().HasLabel("Person").Select("KV").By(gremlingo.Column.Keys), g.GetTraversal().V().HasLabel("Person").Select("KV").By(gremlingo.Column.Values), ).ToList() This basically creates a new Person node with each property i.e. One person with name as Danier and other person with age as 37 whereas I want one person with both or more such properties to be created. Please let me know if there's any better way using gremlin-go. I did try using gremlin and it works, so I need specific help here with Go
Solution:
to add all properties from map to same vertex can be used something like `t := g.AddV("Person") for k, v := range prop { t = t.Property(k,v) }...
Solution
Valentyn Kahamlyk
Valentyn Kahamlyk93d ago
to add all properties from map to same vertex can be used something like t := g.AddV("Person") for k, v := range prop { t = t.Property(k,v) } result, err := t.Next()
amandeep1520
amandeep152093d ago
Thanks, I did this:- g.GetTraversal().WithSideEffect("properties", prop).AddV("Person").As("Vertex").SideEffect( g.GetTraversal().V().Select("properties").Unfold().As("KV").Select("Vertex").Property( g.GetTraversal().V().Select("KV").By(gremlingo.Column.Keys), g.GetTraversal().V().Select("KV").By(gremlingo.Column.Values), ), ).Next() and it works. Next, I am trying to add multiple vertexes with multiple propeties. I want to add thousands of such vertexes with better performance so we can scale as well or is this overcomplicating?
Valentyn Kahamlyk
Valentyn Kahamlyk92d ago
Do you need the properties of all vertices to be the same or different? Usually, when inserting, it is recommended to divide vertices into portions, the size of portion depends on the server. For example for Neptune https://docs.aws.amazon.com/neptune/latest/userguide/best-practices-gremlin-java-batch-add.html For thousands of elements it will work, but the best solution will depend on which server is used
Bulk add vertices and edges in batches - Amazon Neptune
Every query to the Neptune DB runs in the scope of a single transaction, unless you use a session. This means that if you need to insert a lot of data using gremlin queries, batching them together in a batch size of 50-100 improves performance by reducing the number of transactions created for the load.
amandeep1520
amandeep152089d ago
All of the vertices may or may not have similar properties, indeed I will need to batch them. But I was thinking of a way in which I convert the struct to a Map and pass that as an argument The below code works for a single Map, my question is How can we pass an array of maps/dicts having diff set of properties to be inserted to db using gremlin in go? g.GetTraversal().WithSideEffect("properties", prop).AddV("Person").As("Vertex").SideEffect( g.GetTraversal().V().Select("properties").Unfold().As("KV").Select("Vertex").Property( g.GetTraversal().V().Select("KV").By(gremlingo.Column.Keys), g.GetTraversal().V().Select("KV").By(gremlingo.Column.Values), ), ).Next() Thanks, I got it.
Want results from more Discord servers?
Add your server
More Posts
Is it possible to walk 2 different graphs using custom TraversalStrategy in Gremlin?I have 2 different graphs in 2 different Neptune cluster. Both of them can have few reference verticSideEffect a variable, Use it later after BarrierStep?I seek a query that builds a list and then needs to both sum the list's mapped values and divide theMemory issue on repeatI am traversing all nodes occuring in the same cluster given one of the nodes in that cluster. SurpWhich database should i use for my DJ set planning software?Hi, i want to develop a software that lets DJs plan a set (i.e. playlist) and i'm wondering if graphHow will i add unique values to the vertices or edge properties in NeptuneI can't get a doc regarding adding unique data through gremlin. Is there any way to do it, other thaNot getting result in hasId() but id().is() worksI don't get any response using g.V().hasId(48). But when i use g.V().id().is(48). it shows output. Sdotnet `Enumeration has not started. Call MoveNext` if I try to enumerate over a resultI recently try to use gremlin to created a graph and query this graph. Currently I get it working toI can't create an edge in aws neptune using gremlin. I can create vertices. but not edge.import { driver, process as gremlinProcess, structure } from "gremlin"; async function checkOut() {Iterating over responsesI've got a query akin to this in a python application using `gremlin-python`: ``` t = traversal().wAWS Neptune updating gremlin driver to 3.6.2 introduced many bugs to working queriesAfter updating Amazon Neptune engine version from 1.2.0.2 to 1.2.1.0 and the Gremlin.Net (C# nuget) vertex-label-with-given-name-does-not-existERROR with Janusgraph 0.5.3vertex-label-with-given-name-does-not-exist ERROR with Janusgraph 0.5.3 while adding labels to vertiDocumentation states there should be a mid-traversal .E() step?Just wondering if I'm missing something, or if the docs are mistaken. It's possible to do a mid-travDisabling strategies via string in remote driverIs there a way to disable a strategy in a providers implementation without a reference to the class?LazyBarrierStrategy/NoOpBarrierStep incompatible with path-tracking👋🏻 Hi all! In this JanusGraph post (https://discord.com/channels/981533699378135051/1195313165278