I am getting a list of id's from users collection then when I am trying to get by id data from another collection anunturi this error:
FirebaseError: Function CollectionReference.doc() cannot be called with an empty path
<script>
import { db } from "../Utils/fire.js"
import { current_user } from "../Utils/auth.js"
import Room from "./Room.svelte"
async function interestedForUser(){
let query = await db.collection("users").doc($current_user.uid).get()
const listingsIds = await query.data().anunturi_interesat
console.log(listingsIds) //ok
let anunturi = []
for (let id of listingsIds) {
console.log(id, typeof(id)) // ok
let anunt = await db.collection("anunturi").doc(id).get() // nok
let anunt_data = await anunt.data()
if (anunt_data) {
anunturi.push({...anunt_data, listingId:id})
}
}
return anunturi
}
</script>
{#await interestedForUser()}
<p class="text-center mt-12">Se incarca...</p>
{:then listings}
{console.log("In template:", listings, listings.length)} //ok (but why?)
{#if listings.length > 0} // this doesn't get rendered..
{#each listings as camera }
<Room {camera}/>
{/each}
{:else}
<p class="text-center mt-12">Nu ai postat nici un anunt</p>
{/if}
{:catch error}
<p style="color: red">{error.message}</p>
{/await}
UPDATE:
The issue was in the <Room {camera}/> component. A child of Room component had a firestore reference undefined.
