f-miyu / Plugin.CloudFirestore

MIT License
121 stars 44 forks source link

Inserting into subcollections #82

Open rezamohamed opened 3 years ago

rezamohamed commented 3 years ago

I have a collection where the root is the UserID, and then I have a Sub-Collection of 'businesscards'. I am trying to insert new docs to this subcollection.

This code creates new documents on each insert with new DocId's at the UserID level with the Collection Name just called 'businesscards' for each new DocId that got create. How would I insert the new docs into the collection called 'businesscards'? I don't have the Document ID for the 'businesscards' subcollection.

                var x = 
                    await CrossCloudFirestore.Current.Instance
                    .Collection(userId)
                    .Document()
                    .Collection('businesscards')
                    .AddAsync(doc);
rezamohamed commented 3 years ago

Not sure if this is the right approach, but I gave the Document the same name as the Collection

var x = await CrossCloudFirestore.Current.Instance .Collection(userId) .Document('businesscards') .Collection('businesscards') .AddAsync(doc);