Reputation: 1169
Per a different StackOverflow answer, we can generate random Firestore IDs using:
String id = db.collection("collection_name").document().getId();
Will running this code have any effect on the actual Firestore database?
As an example, say we run the code above 100,000 times to get 100,000 unique IDs to optionally use later, and we store these IDs in a list - will there by any effect on Firestore if we do not take any further action?
Use case is to use some of these later by assigning to the id field of objects that get added to a collection in a Firestore transaction as so:
tAssignment.setID(idList.get(nextIndex));
final DocumentReference assignmentDocRef = firestore.document(BuildConfig.FIRESTORE_ROOT_FULL_PATH + tAssignment.getId());
transaction.set(assignmentDocRef, tAssignment);
Just want to make sure generating a lot of these - some of which should never be saved to Firestore - is safe.
Upvotes: 0
Views: 47
Reputation: 317692
Will running this code have any effect on the actual Firestore database?
No, the ID is generated randomly by the SDK on the client. Nothing will happen in the database until you actually write a document using this string (if you even choose to use it).
Upvotes: 1