Very sorry about the formatting, I thought html would be interpreted. Here is the "plain text" version:
Hello everyone,
I'm having trouble doing an insert many in which I ignore the insert step if the node already exists. Currently, my solution which doesn't check if the node exists and instead always inserts looks like this.
# suppose objects is a list of dictionaries of shape [{"foo": "value", "bar": "value", ..}, ..]
g.inject(objects)
.unfold().as_("objects")
.addV("foo").as_("f_vertex")
.sideEffect(
select("objects")
.unfold().as_("kv")
.select("f_vertex").property(select('kv').by(Column.keys), select('kv').by(Column.values))
)
.addV("bar").as_("b_vertex")
.sideEffect(
select("objects").select("foo").as_("foos")
.select("b_vertex").property("value", select("foos").unfold())
.addE("test").from_(select("p_vertex")).to(select("b_vertex"))
).next()
This works flawlessly. I'm now trying to make it so that the bar insert is conditional on the non-existence of the node. My current attempt looks like this:
g.inject(objects)
.unfold().as_("objects")
.addV("foo").as_("f_vertex")
.sideEffect(
select("objects")
.unfold().as_("kv")
.select("f_vertex").property(select('kv').by(Column.keys), select('kv').by(Column.values))
)
.sideEffect(
select("objects").select("bar").unfold().as_("bars")
.V().has("bar", "value", select("bars").unfold()
).coalesce(
unfold(),
addV("bar").property("value", select("bars").unfold())
)
).next()
But then no bar nodes are added at all. I've tried several other similar combinations (pulling select outside of the sideEffect, playing with fold/unfold), but I can't seem to get it right.
I would be very grateful if someone could explain to me what's wrong and direct me to the!
Best