【发布时间】:2019-07-20 12:47:16
【问题描述】:
我会创建一个 react-native 应用程序。现在我不确定,在集合中构建数据的最佳方式是什么。
按照我的情况: 我有两个集合公司和用户。两个收藏都有会员合同。那么存储数据的最佳方式是什么?
方法一:
{
users: [
"id": 1,
"firstName": "John",
"lastName": "Smith",
"gender": "man",
"age": 32,
"subcollection_company": [
{
"id": 1,
"name": "Company LLC",
"membership_status": "REQUESTD",
}
],
],
companies: [
"id": 1,
"name": "Company LLC",
"subcollection_users": [
{
"id": 1,
"firstName": "John",
"lastName": "Smith",
"membership_status": "REQUESTED",
}
],
],
}
方法2(数组代替子集合):
{
users: [
"id": 1,
"firstName": "John",
"lastName": "Smith",
"gender": "man",
"age": 32,
"array_company": [
{
"id": 1,
"name": "Company LLC",
"membership_status": "REQUESTED",
}
],
],
companies: [
"id": 1,
"name": "Company LLC",
"array_users": [
{
"id": 1,
"firstName": "John",
"lastName": "Smith",
"membership_status": "REQUESTED",
}
],
],
}
方法3(像sql这样的老方法):
{
users: [
"id": 1,
"firstName": "John",
"lastName": "Smith",
"gender": "man",
"age": 32,
],
companies: [
"id": 1,
"name": "Company LLC",
],
user_comany: [
{
userref: 'users/1',
companyref: 'companies/1',
"membership_status": "REQUESTD",
}
]
}
【问题讨论】:
标签: mongodb firebase google-cloud-firestore nosql