Home > other >  Firebase Cloud Firestore: Creating a new document in a collection for every UID
Firebase Cloud Firestore: Creating a new document in a collection for every UID

Time:12-13

I want to implement a badge system into my Firebase project, but I already have a lot of users. I want to take all the UIDs of my existing users, and create a new corresponding document for them in my new collection, userinfo.

I've searched the docs and I cannot find a way to do this. Can I get some help creating the documents?

CodePudding user response:

If you want to create a new document for each user that already exists in the (users) collection to another (userinfo) collection, then you have to read all documents from the "users" collection and perform a write operation in the "userinfo" collection. But bear in mind to not perform such an operation on the client, but in a trusted environment, such as a server that you control, or using Cloud Functions for Firebase.

  • Related