Reputation: 1998
from the firestore doc
In some cases, it can be useful to create a document reference with an auto-generated ID, then use the reference later. For this use case, you can call doc().
import { collection, doc, setDoc } from "firebase/firestore";
// Add a new document with a generated id
const newCityRef = doc(collection(db, "cities"));
// later...
await setDoc(newCityRef, data);
Behind the scenes, .add(...) and .doc().set(...) are completely equivalent, so you can use whichever is more convenient.
my question is that does const newCityRef = doc(collection(db, "cities"));
count as 'read' or 'write' without using setDoc(newCityRef, data)
?
Let's say if I generate 100 document references but don't save them at all, my 'read' or 'write' count is 0 or 100?
Upvotes: 1
Views: 635
Reputation: 50930
No, you are charged only when you read or save data from Firestore. The references are just created by Firebase SDK on client side.
Upvotes: 5