I have a vertex which has a list property, and I want to replace the values in said property and project out the result in a specific format. For context, let's assume the following data:
g.AddV("Post").property("id", "1")
.property(list, "Tags", "gremlin")
.property(list, "Tags", "new")
I want to be able to set the Tags
property.
What I've tried so far:
g.V("1")
.sideEffect( properties("Tags").drop() )
.property(list, "Tags", "gremlin")
.property(list, "Tags", "closed")
.property(list, "Tags", "solved")
.project("Tags").By(values("Tags"))
What I would expect is the following
{
"Tags": [
"gremlin",
"closed",
"solved",
]
}
But I instead get the error Project By: Next: The provided traverser of key "Tags" maps to nothing.
So it appears as if the Tags
property was deleted in its entirety.
If I do a query afterwards
g.V("1").project("Tags").By(values("Tags"))
I get the expected result:
{
"Tags": [
"gremlin",
"closed",
"solved",
]
}
So the data must have been changed. If I try without projecting, the result contains the new values.
g.V("1")
.sideEffect( properties("Tags").drop() )
.property(list, "Tags", "gremlin")
.property(list, "Tags", "closed")
.property(list, "Tags", "solved")
Resulting in:
{
"id": "1",
"label": "Post",
"type": "vertex",
"properties": {
"Tags": [
{
"id": "4eaf5599-511c-4245-aaf8-15c828073fac",
"value": "gremlin"
},
{
"id": "75e3ad96-a503-4608-a675-e28f3ffc2ab4",
"value": "closed"
},
{
"id": "aea1a33c-bd8e-47bb-b294-f01db8642db5",
"value": "solved"
},
]
}
}
But this leaves me unable to project the result.
How can I both update the data and project it?
Other things I've tried:
- Adding a
barrier()
step after thedrop()
step, didn't work - Adding a
barrier()
step after thesideEffect()
step, didn't work - Adding a
barrier()
step before theproject()
step, didn't work - Doing the same as the above three, but with
.fold().unfold()
instead, didn't work - Replacing the
project()
step withoptional(g.V("1").project("Tags").by(values("Tags")))
- this one works by refetching the vertex but is expensive.