in Education by
After reading the documentation they recommend not using nested data structure. I am thinking this is the best way for my data but I am not sure how to add the tripId to the hotels collection. My other option is having the user enter the "BOL" for each hotel entry... My problem with that method is how do I query the date to see all the hotels that match the "trip"? users: - gCFiwSLwBeg87N6GfeofFxIAZyi2 - UID: gCFiwSLwBeg87N6GfeofFxIAZyi2 - firstName: "James" - email: "[email protected]" trips: - "random document id" - bol: "1234567" - startDate: "1/3/2022" - destination: "Sacramento, CA" - userID: "Users UID" - foodTotal: "100" - hotelTotal: "240" - "random document id" - bol: "256976" - startDate: "2/5/2022" - destination: "Orlando, FL" - userID: "Users UID" - foodTotal: "150" - hotelTotal: "400" hotels: - "random document id" - tripId: ? - date: "1/4/2022" - destination: "Sacramento, CA" - userID: "Users UID" - name: "Hotel Inn" - cost: "120" - "random document id" - tripId: ? - date: "1/5/2022" - destination: "Sacramento, CA" - userID: "Users UID" - name: "Hotel Inn" - cost: "120" Here is the function I am currently using to add Hotels to firebase. class FirebaseHotelRepository: HotelRepositoryProtocol { private let db = Firestore.firestore() func addHotel(hotel: Hotel, completion: @escaping (Result) -> Void) { do { var addedHotel = hotel addedHotel.userId = Auth.auth().currentUser?.uid let _ = try db.collection("hotels").addDocument(from: addedHotel) } catch { fatalError("Unable to encode trip: \(error.localizedDescription)") } } } class AddHotelViewModel: ObservableObject { private let repo: HotelRepositoryProtocol var name: String = "" var location: String = "" var date = Date() var cost: String = "" @Published var saved: Bool = false init(repo: HotelRepositoryProtocol) { self.repo = repo } func addHotel() { let hotel = Hotel(bol: bol, name: name, location: location, date: date, cost: cost, color: UIColor(color).hexStringFromColor()) repo.addHotel(hotel: hotel) { result in switch result { case .success(let savedHotel): DispatchQueue.main.async { self.saved = savedHotel == nil ? false : true } case .failure(let error): print(error.localizedDescription) } } } } 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
From this documentation: 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(): Here's a sample code that you can refer to: let trips = db.collection("trips").addDocument(data: [ // trips' data ]) // This will append tripId to the `addedHotel` addedHotel["tripId"] = trips.documentID let hotels = db.collection("hotels").addDocument(from: addedHotel) The above code should get the document ID of the trips' and you can manually append or construct the data that you should pass to the hotels` document. You can find more relevant information here.

Related questions

0 votes
    Right now my firebase cloud firestore looks like this: const db = fire.firestore(); db.collection(" ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I have an application I'm building with Firebase. Essentially, I'm trying to build an authentication system ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    I am trying to intitialize my Collection View Model which holds a list of [Users] with a firebase snap ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
0 votes
    Error: Type com.google.android.gms.common.internal.zzf is referenced as an interface from `com.google. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 14, 2022 in Education by JackTerrance
0 votes
    My node 8 function, hosted at Firebase Cloud Functions isn't working as expected. I've a toLocaleString ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    My node 8 function, hosted at Firebase Cloud Functions isn't working as expected. I've a toLocaleString ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    My code: PhoneAuthProvider.getInstance().verifyPhoneNumber( phoneNumber, // Phone number to verify 60, // Timeout ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    I replaced the Google Analytics SDK with the Firebase SDK. I'm looking to generate some of the previously- ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 19, 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
    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 am using Firebase authentication and react-redux in my app. I added firebase.auth().onAuthStateChanged to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    I am using Firebase authentication and react-redux in my app. I added firebase.auth().onAuthStateChanged to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    I am getting the error 'Uncaught TypeError: firebase.auth is not a function'. My code was working perfectly ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    I'm currently trying Firebase Remote Config on Android. I gave a parameter a value: 2.2 but when ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 13, 2022 in Education by JackTerrance
0 votes
    It is possible to use email verification with firebase but instead of sending a link they have to click, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
...