Always Learner
Always Learner

Reputation: 2952

Does the attempt to write a document cost a write operation in Cloud Firestore?

If I use the following line of code for the first time (when database is empty), my user is correctly added to the database.

db.collection("users").document(uid).set(userObject);

If I use the same line of code again, the user is not added anymore, obviously because is already there.

My question: Does the attempt to write a document that already exists in database cost me a write operation?

Is it necessary to get a reference first, check if the uid already exists in database in order to write the user? Does this also cost a read operation?

Thanks!

Upvotes: 0

Views: 75

Answers (1)

Dan McGrath
Dan McGrath

Reputation: 42008

"Does the attempt to write a document that already exists in database cost me a write operation?"

Yes, the write is still performed and still billed.

"Is it necessary to get a reference first, check if the uid already exists in database in order to write the user?"

If you know the uid you can always write it without checking first.

"Does this also cost a read operation?"

Yes, reading the document first costs a document read.

Upvotes: 1

Related Questions