构建noSQL数据库的最实用方法是什么?

时间:2019-02-18 13:59:54

标签: javascript firebase nosql

请考虑以下三个相同信息的数据结构示例:

//the properties are nested
{
  clientOne: {
    users: {
      userOne: {
        userType: "admin"
      },
      userTwo: {
        userType: "user"
      }
    },
    projects: {
      projectOne: {
        elements: {
          elementOne: "a",
          elementTwo: "b",
          elementThree: "c"
        },
        collections: {
          collectionOne: {
            elementOne: {
              elementTwo: {
                elementThree: true
              }
            }
          }
        }
      }
    }
  }
}

在上面的每个信息都位于同一位置,子数据嵌套到其父级。

//the properties are flattened, parent contains it's children
{
  clients: {
    clientOne: {
      users: {
        userOne: true,
        userTwo: true
      },
      projects: {
        projectOne: true
      }
    }
  },
  users: {
    userOne: {
      userType: "admin"
    },
    userTwo: {
      userType: "user"
    }
  },
  projects: {
    projectOne: {
      elements: {
        elementOne: true,
        elementTwo: true,
        elementThree: true
      },
      collections: {
        collectionOne: true
      }
    }
  },
  elements: {
    elementOne: "a",
    elementTwo: "b",
    elementThree: "c"
  },
  collections: {
    collectionOne: {
      elementOne: {
        elementTwo: {
          elementThree: true
        }
      }
    }
  }
}

在上面的示例中,属性彼此“独立”,父级仅指向其子级所在的路由。

//the properties are flattened, child contains it's parent
{
  clients: {
    clientOne: true
  },
  users: {
    userOne: {
      userType: "admin",
      clientId: "clientOne"
    },
    userTwo: {
      userType: "user",
      clientId: "clientOne"
    }
  },
  projects: {
    projectOne: true
  },
  elements: {
    elementOne: {
      value: "a",
      projectId: "projectOne"
    },
    elementTwo: {
      value: "b",
      projectId: "projectOne"
    },
    elementThree: {
      value: "c",
      projectId: "projectOne"
    }
  },
  collections: {
    collectionOne: {
      projectId: "projectOne",
      value: {
        elementOne: {
          elementTwo: {
            elementThree: true
          }
        }
      }
    }
  }
}

在上面的示例中,子级指向其直接父级的ID。

这三个数据库包含相同的信息,但是方式不同。哪些用例需要哪种方法?

0 个答案:

没有答案