我正在尝试在 ionic 4 应用程序/角度应用程序中查询 Firestore 子集合。我的数据库如下所示 people(id) ----> tasks(id)
{ description : this is a description about a cat,<br>
title: this is a cat <br>
category: cat }
我正在使用 Firestore 函数来查询集合中的所有数据。这是 Firestore 函数的样子:
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin'
admin.initializeApp()
export const getFeed = functions.https.onCall(async (req,res) =>{
const docs = await
admin.firestore().collection('people').limit(5).get()
return docs.docs.map(doc => {
return {
postID: doc.id,
...doc.data()
}
})
})
打字稿 home.ts 文件如下所示:
const getFeed = this.aff.httpsCallable('getFeed')
this.posts = getFeed({}).subscribe(data=> {
console.log(data)
// this.posts = data
})
}
我尝试使用 array-contains 选项进行查询,但它不起作用。该数组在控制台上显示为空。
export const getFeed = functions.https.onCall(async (req,res) =>{
const docs = await
admin.firestore().collection('people').where("category",
"array-
contains", "cat").limit(5).get()
return docs.docs.map(doc => {
return {
postID: doc.id,
...doc.data()
}
})
})
慕妹3242003
郎朗坤
相关分类