I’m looking for a complete, working example of an upsert operation that I can basically paste in to the mutation section on Ratel. I’ve tried many, many queries but have not seen anything but either duplicate values or errors.
Ultimately, I would like something like this:
<foo>: string @index(exact) @upsert . <is_a_bar>: uid @count @reverse . <bar>: string @index(exact) @upsert .
and I’d like to be able to add
is_a_bar to an existing
foo (and add a new
bar if necessary), without creating a duplicate.
Based on what I see in the documentation, it seems like this should be automatic: https://docs.dgraph.io/query-language/#upsert-directive . However, I’ve been searching comments here and see a lot older discussions suggesting you need to do your upsert manually: first run a query to see if the value exists, create it if it doesn’t, then you can create the value, else use the existing value. That would work, of course, but it means that
@upsert isn’t useful (for me). I mean, I can manually upsert by hand but I was hoping that the database would take care of it for me. I also found this, which seems to back up the comments: https://docs.dgraph.io/howto/#upserts
I’m hoping I’m just missing something obvious here. If upserts have to be done manually in client code, what does