我一直在尝试实现一些从 Cloud Firestore 读取数据的 Cloud Functions。我想在本地测试这些,但是我无法运行 Cloud Firestore 模拟器。我的假设是问题出在哪里,但可能在其他地方 - 如果是这种情况,请告诉我。
这是我的功能:
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin'
admin.initializeApp()
//Functions to fetch the documents in the user collection and send them to the client.
export const getUserDocs = functions.https.onRequest((request, response) => {
admin.firestore().doc('/Users/{documentId}').get()
.then(snapshot => {
const data = snapshot.data()
response.send(data)
})
.catch(error => {
response.status(500).send(error)
})
})
Run Code Online (Sandbox Code Playgroud)
这是我运行命令时得到的错误firebase serve --only functions:
Carlo@Carlos-Air-2 functions % firebase serve --only functions
? Your requested …Run Code Online (Sandbox Code Playgroud) firebase google-cloud-functions google-cloud-firestore firebase-cli