约会应用程序 - 我需要在 Firebase Firestore 中使用哪种数据库结构来查询除不喜欢我的用户之外的所有用户?

Dating app - Which database structure do I need in Firebase Firestore to query all users except those who disliked me?

我正在使用 React NativeFirebase Cloud Firestore 创建一个约会应用程序。在我的应用程序中,用户可以不喜欢其他用户将他们排除在下一个查询之外。

我应该使用哪种数据库结构来执行 Firestore 查询


当您不喜欢某人时,用户 ID 将存储在您的用户文档中的数组中。 Firestore 查询仅提供 'array-contains' 运算符以根据数组值进行过滤。所以我需要查询 "array-NOT-contains" 但是 Firestore 没有提供。


我的 Firestore 数据库结构:

collection('user').doc('userID').match.dislike[dislikedUserID1, dislikedUserID2,...]

screenshot: Firestore Database

你是对的,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))
})