Firestore 在 Angular Fire 7.5.0 上命名数据库
app.module.ts 上的 Angular Fire 配置
provideFirebaseApp(() => initializeApp(environment.firebase)),
provideAuth(() => getAuth()),
provideFirestore(() => getFirestore('test')), //use named firestore database
正确读取集合工作
private firestore: Firestore = inject(Firestore);
private collectionName = environment.firestoreCollections.example;
const c = collection(this.firestore, this.collectionName);
const q = query(c, orderBy('name'));
const querySnapshot = await getDocs(q);
const data = querySnapshot.docs.map(item => {
return { ...item.data(), id: item.id }
}) as Example[];
return data;
但在计算具有聚合查询的文档时返回错误
private firestore: Firestore = inject(Firestore);
private collectionName = environment.firestoreCollections.example;
const c = collection(this.firestore, this.collectionName);
const snapshot = await getCountFromServer(c);
return snapshot.data().count;
[
{
"error": {
"code": 400,
"message": "Missing routing header. Please fill in the request header with format x-goog-request-params:project_id=example-2&database_id=test. Please refer to https://firebase.google.com/docs/firestore/manage-databases#access_a_named_database_with_a_client_library for more details.",
"status": "INVALID_ARGUMENT"
}
}
]
是否有将 Angular Fire 与命名 Firestore 数据库集成或关于此错误的想法?当我使用(默认)firestore 数据库时,聚合查询可以正常工作
我正在使用 vue.js,并且在使用aggregationFunction 时遇到相同的错误 - 可能是由于同一项目中拥有多个数据库的 beta 状态?
我尝试通过 firebase 托管标头设置来设置该标头,但无法使其工作。