Javascript Firebase云函数返回空集合
我正在尝试从swift应用程序中使用云函数获取集合的所有文档。我看到文件从firebase控制台返回,但在我的swift应用程序中,我总是得到一个空结果。我试过函数的两种变体Javascript Firebase云函数返回空集合,javascript,swift,firebase,google-cloud-functions,Javascript,Swift,Firebase,Google Cloud Functions,我正在尝试从swift应用程序中使用云函数获取集合的所有文档。我看到文件从firebase控制台返回,但在我的swift应用程序中,我总是得到一个空结果。我试过函数的两种变体 export const fetchCollection = functions.https.onCall(async (data, context) => { try { if (!context.auth) return { status: 'error', code: 401, mess
export const fetchCollection = functions.https.onCall(async (data, context) => {
try {
if (!context.auth) return { status: 'error', code: 401, message: 'Not signed in' }
const snapshot = await firestore.collection(`/${data.collectionName}`).get()
const collection = new Map()
snapshot.forEach (doc => {
collection.set(doc.id, doc.data())
})
return collection
} catch (error) {
return new functions.https.HttpsError(error.code, error.message)
}
})
这是我的swift密码
functions.httpsCallable("fetchCollection").call(request) { result, error in
if error == nil {
print("\(Date()) Result: \(result?.data as? [String: Any])")
}
}
如果我在云函数中使用snapshot.docs.map(doc=>doc.data()),结果总是[:]并且是零
export const fetchCollection = functions.https.onCall(async (data, context) => {
try {
if (!context.auth) return { status: 'error', code: 401, message: 'Not signed in' }
const snapshot = await firestore.collection(`/${data.collectionName}`).get()
const collection = new Map()
snapshot.forEach (doc => {
collection.set(doc.id, doc.data())
})
return collection
} catch (error) {
return new functions.https.HttpsError(error.code, error.message)
}
})
而且,xCode中的时间戳与firebase控制台中的日志不同
我做错了什么。谢谢你的帮助