When to use the upsert directive

I don’t understand when / if I need to use the upsert directive on the schema when doing an upsert

I can create the upsert by following these docs, but I don’t seem to need the upsert directive.

What am I missing? I thought maybe the upsert directive enforces uniqueness on the predicate it is attached to but that does not seem to be the case.

I was confused with it some months ago

Any help would be appreciated.

Thanks

1 Like

Cameron, it is simple.

Upsert directive is one thing and upsert procedure is another thing. Do not confuse the two. You can do any procedure, but technically you need to have upsert directive with an indexing on that occasion. This avoids conflicts in the transaction. Between transaction opening and commit.

If you do not use Upsert directive in Schema, I believe that conflicts may occur at some future time in your transactions.

BTW, Dgraph does not check the uniqueness of the attribute in a mutation just because it has @upsert in its Schema. You need to do yourself both.

Cheers.

1 Like

Yes I am a little simple :sweat_smile:

Thanks for this, it clears up my confusion.

Cheers
Cam

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.