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
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)
}
result, err := t.Next()