Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 云firestore中的好友关系数据模型_Firebase_Google Cloud Firestore - Fatal编程技术网

Firebase 云firestore中的好友关系数据模型

Firebase 云firestore中的好友关系数据模型,firebase,google-cloud-firestore,Firebase,Google Cloud Firestore,我希望在我的云firestore模型中有此关系模型: () 关系模型 用户识别码 用户识别码 地位 操作\u用户\u id 状态代码 代码意义 0待定 1接受 2谢绝 3阻塞 我对Firebase不太熟悉&不太熟悉SQL。但我发现我不能用CloudFireStore进行“或”查询。如何将其转换为云Firestore模型 例如,为了获得好友列表,我必须在查询中执行or操作: 好友列表 检索所有用户的好友。此处,用户1是已登录的用户 SELECT * FROM `relationship

我希望在我的云firestore模型中有此关系模型: ()

关系模型

  • 用户识别码

  • 用户识别码

  • 地位

  • 操作\u用户\u id

状态代码 代码意义

0待定

1接受

2谢绝

3阻塞

我对Firebase不太熟悉&不太熟悉SQL。但我发现我不能用CloudFireStore进行“或”查询。如何将其转换为云Firestore模型

例如,为了获得好友列表,我必须在查询中执行or操作:

好友列表

检索所有用户的好友。此处,用户1是已登录的用户

SELECT * FROM `relationship`
  WHERE (`user_one_id` = 1 OR `user_two_id` = 1)
  AND `status` = 1


您不希望将用户ID存储在两个单独的字段中,而是希望将其存储在单个数组中:

userIds: [1, 2]
使用文档中的该字段,您可以执行以下操作来检测
1
userid
一部分的所有文档:

relationsRef.where('userIds', 'array-contains', 1);
再加上你的其他情况:

relationsRef.where('userIds', 'array-contains', 1)
            .where('status', '=', 1)

如果您是Firestore和NoSQL数据库的新手,我建议您阅读和观看。花几个小时在这些问题上,将为您节省大量的时间。

感谢您提供详细的答案。