【发布时间】:2021-03-25 04:52:17
【问题描述】:
我正在从用户集合中获取 id 列表,然后当我尝试从另一个集合中获取 id 数据时出现此错误:
FirebaseError:无法使用空路径调用函数 CollectionReference.doc()
<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}
更新:
问题出在<Room {camera}/> 组件中。 Room 组件的子组件具有未定义的 firestore 引用。
【问题讨论】:
标签: javascript google-cloud-firestore svelte-3