简体   繁体   English

firebase 模拟器数据未保存并从某些缓存中检索

[英]firebase emulator data not saved and retrieved from some cache

Getting data from firestore emulator works fine, manually added documents.从 firestore 模拟器获取数据工作正常,手动添加文档。

export const getMaterials = async (companyID: string): Promise<Material[]> => {
   const materials = await getDocs(collection(db, 
   `${COMPANIES}/${companyID}/materials`))
 return materials.docs.map<Material>((doc) => <Material>{ id: doc.id, ...doc.data() })
}

Saving also return with success but the data is not shown in the emulator UI but return from the above function the records from the emulator and the newly added records.保存也返回成功但是数据没有显示在模拟器UI中但是从上面的function返回模拟器的记录和新添加的记录。

The data disappear after refreshing the app and the emulator.刷新应用程序和模拟器后数据消失。

 export const setMaterial = async (
  companyID: string,
  id: string
): Promise<any> => {
const docData = {
    companyID: companyID,
    id: id,
    name: name
  }
     const ret = await addDoc(collection(db, `${COMPANIES}/${companyID}/materials`), 
     docData)
     return ret
  } 

Deleting documents from the emulator keep on returning from the getMaterial function. Again until restarting the app and the emulator.从模拟器中删除文档继续从 getMaterial function 返回。再次直到重新启动应用程序和模拟器。

Any idea where these guest documents is saved and why it's not saving to the emulator.知道这些来宾文档保存在哪里以及为什么不保存到模拟器中。

related: Firebase Firestore Emulator UI is not showing any data, but data is being returned in app query相关: Firebase Firestore Emulator UI 未显示任何数据,但应用查询中正在返回数据

const config = {
  apiKey: 'AIz....3Jk1',
  projectId: 'local',
  authDomain: 'app.localhost.dev',
}

Changing projectId from local to the current project getting from the command将 projectId 从本地更改为从命令获取的当前项目

firebase projects:list

Solved the problem解决了问题

I've come across the same issue.我遇到过同样的问题。 Mine happened to be similar yet a bit different problem.我的碰巧是相似但有点不同的问题。

THE ISSUE问题

My app was part of project-1 and Firestore part of project-2 .我的应用程序是project-1的一部分,Firestore 是project-2的一部分。

My dumb mistake was trying to initialize Firestore - getFirestore() - with configuration for project-1 a connected it to emulator - connectFirestoreEmulator .我的愚蠢错误是试图初始化 Firestore - getFirestore() - 使用project-1的配置将其连接到模拟器 - connectFirestoreEmulator That led to the same issues described by OP.这导致了 OP 描述的相同问题。

TL;DR长话短说

Check twice, if you are connecting to the right Firestore via getFirestore() .如果您通过getFirestore()连接到正确的 Firestore,请检查两次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM