reactjs - 约会应用 - 我需要在 Firebase Firestore 中使用哪种数据库结构来查询除不喜欢我的用户之外的所有用户?
问题描述
我正在使用React Native和Firebase Cloud Firestore创建约会应用程序。在我的应用程序中,用户可以不喜欢其他用户以将他们排除在下一个查询之外。
我应该使用哪种数据库结构来执行 Firestore 查询?
当您不喜欢某人时,用户 ID 将存储在您的用户文档中的一个数组中。Firestore 查询仅提供“array-contains”运算符来根据数组值进行过滤。所以我需要查询“array-NOT-contains”,但 Firestore 不提供它。
我的 Firestore 数据库结构:
collection('user').doc('userID').match.dislike[dislikedUserID1 ,dislikedUserID2,... ]
解决方案
你是对的,where
它没有提供像“array_does_not_contain”这样的子句。只需做一个不太合格的查询并从结果中减去。对于广受欢迎的人来说,这可能是一个浪费的查询,但假设大多数人都很可爱……
const adorableMe = firebase.auth().currentUser
collection('user').where(/* they might think I'm a cutie pie */).get().then(snapshot => {
// filter result to exclude the (tiny!) set of users who don't fancy me
return snapshot.docs.filter(doc => !doc.data().dislikes.includes(adorableMe.id))
})
推荐阅读
- c# - 不要在测试中验证 JWT 过期
- asp.net - 使用 app.UseMvc() 或 app.UseEndpoints 在 asp.net core mvc 项目中设置路由有什么区别?
- blazor - 调试 Blazor WASM(Aspnet 托管)时无法使用热重载
- ios - 如何使用 UIPanGestureRecognizer 围绕自己的中心旋转 SCNNode?
- python - 如何从 Tkinter 对象入口获取数据?
- php - 在 PHP 上裁剪图像的空白部分
- python - 在一张图中绘制许多时间序列列
- angular - Angular 11 NgRx 状态管理以最有效的方式处理订阅和取消订阅
- sharepoint - Excel 脚本和流程问题 - 找不到脚本。它可能已被取消共享或删除。clientRequestId:ebf53c05-7f24-4537-a91d-9edb8903eb8c
- activemq-artemis - 以前版本的 ActiveMQ Artemis 可以与当前版本交互吗?