in Education by
Right now my firebase cloud firestore looks like this: const db = fire.firestore(); db.collection("groupFavs/"+groupID+ "/"+currentUserUID).add({favs: likedData}) The code above creates a collection called groupFavs, a document called groupID and another collection with the current users id. In the image I have above, it keeps creating documents for the users likes when i just want the currentuser id to only have one list in it which will be all their liked data. But instead it just keeps making multiple of them and I think its because of .add I've tried using set but that wont work. Where am I going wrong? db.collection("groupFavs2") .doc(groupID).collection(currentUserUID) .set({ favs: likedData }) I basically want to do something like this above but my logic is off in regards to the nested collection because what im calling above does not work JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You can circumvent the string concatenation as well as the nested .collection .doc chain by using string interpolation as follows: const collectionRef = db.collection(`groupFavs/${groupID}/${currentUserUID}`) collectionRef.add({favs: likedData}) In regards to the multiple documents, you are adding a new document under the sub collection (matching the users id). Ideally this would look something like this: Group Favs 1st UserId Like 1 doc Like 2 doc 2st UserId Like 1 doc Like 2 doc Where the like doc can contain information related to the like such as image or liked boolean property. If instead what you would like to do is keep a list of the users likes under their doc you can do it as follows: const docRef= db.doc(`groupFavs/${groupID}/${currentUserUID}`) const newLikeData = { likes: firestore.FieldValue.arrayUnion() } docRef.set({favs: likedData}, {merge:true}) arrayUnion will append whatever data is in . Alternatively, you could query for the current likes list under the users doc, manually append the information and pass the entire object to a update or setDoc with merge: true.

Related questions

0 votes
    this is my first question here, i hope you can help me. I've been trying to get a specific path ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    this is my first question here, i hope you can help me. I've been trying to get a specific path ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    I have this operation EventModel data = EventModel(_nameEvent, _passEvent, _localEvent, _dateEventString); HashMap ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
    I am trying to add some items to a TreeView Control: TV1.Nodes.Add("key1", "Test1") 'Works TV1. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 28, 2022 in Education by JackTerrance
0 votes
    In Firestore documentation said: There are no additional costs for using cursors, page tokens, and limits. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
    In Firestore documentation said: There are no additional costs for using cursors, page tokens, and limits. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 8, 2022 in Education by JackTerrance
0 votes
    I tried to find out how to use firestore local emulator for python and for testing purpose. But I ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I'm currently using Cloud Firestore as my backend for a mobile app. I've got basic payments working ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 19, 2022 in Education by JackTerrance
0 votes
    Cloud Functions and Firebase Functions (or "Cloud Functions for Firebase") both look the same. Please describe the ... between these? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    Google provides two cloud-based data storage services Google Cloud Datastore and Firebase (after its acquisition). ... vs Firebase? Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    After reading the documentation they recommend not using nested data structure. I am thinking this is the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    I'm querying a collection for a specific document and trying to get the document-ID from the result of ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I have a blade template that creates a form. The form uses a foreach loop to iterate through a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 10, 2022 in Education by JackTerrance
0 votes
    I have a blade template that creates a form. The form uses a foreach loop to iterate through a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 22, 2022 in Education by JackTerrance
0 votes
    document which is considered output after processing and by adding more data to this output it can be used as input is termed as Select the correct answer from above options...
asked Dec 24, 2021 in Education by JackTerrance
...