我正在尝试在 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() } }) })
2 回答
![?](http://img1.sycdn.imooc.com/54586870000183e302200220-100-100.jpg)
慕妹3242003
TA贡献1824条经验 获得超6个赞
您的问题不是很清楚,但看起来category
您的数据库字段实际上并不是列表类型字段。 array-contains
仅当值是一个列表时才有效,如果它只是一个字符串值,则无效。如果它只是一个字符串,则对其使用==
过滤器。
![?](http://img1.sycdn.imooc.com/533e4c3300019caf02000200-100-100.jpg)
郎朗坤
TA贡献1921条经验 获得超9个赞
我通过采用数组字段类型而不是子集合找到了解决方法。
这是我的代码示例:
var coll = this.firestore.collection('credentials', ref => ref.where('tags', 'array-contains-any', ['agile']).orderBy('shortName')); // selects part of collection where roomId = roomStripped, sorted by name
返回 coll.snapshotChanges();
我有一个名为凭据的主要集合,以及每个文档中的标签列表。
添加回答
举报
0/150
提交
取消