MongoDB数据库设计用于用户及其数据

时间:2018-01-05 02:04:44

标签: mongodb

MongoDB和数据库的新功能。我正在尝试用Express和MongoDB制作一个基本的属性应用程序。

我正在寻找一些帮助来解决这个问题的最佳方法。

基本上,我的应用程序会有房东和房客。每个房东都会有一堆存储信息的属性。租赁条款,租户名称,维护请求,图像等等。

租户可以注册并与他们居住的房产相关联。他们可以提交维护表格等。

这是一个好方法吗?一切都应保存在同一个系列中吗?感谢。

{
  "_id": "507f1f77bcf86cd799439011",
  "user": "Corey",
  "password": "hashed#PASSWORD",
  "email": "corey@email.com",
  "role": "landlord",
  "properties": [
    {
      "addressId": "1",
      "address": "101 Main Street",
      "tenant": "John Smith",
      "leaseDate": "04/21/2016",
      "notes": "These are my notes about this property.",
      "images": [ "http://www.imagelink.com/image1", "http://www.imagelink.com/image2", "http://www.imagelink.com/image3"]
    },
    {
      "addressId": "2",
      "address": "105 Maple Street",
      "tenant": "John Jones",
      "leaseDate": "01/01/2018",
      "notes": "These are my notes about 105 Maple Ave property.",
      "images": ["http://www.imagelink.com/image1", "http://www.imagelink.com/image2", "http://www.imagelink.com/image3"],
      "forms": [
        {
          "formType": "lease",
          "leaseTerm": "12 months",
          "leaseName": "John Jones",
          "leaseDate": "01/01/2018"
        },
        {
          "formtype": "maintenance",
          "maintenanceNotes": "Need furnace looked at. Doesn't heat properly.",
          "maintenanceName": "John Jones",
          "maintenanceDate": "01/04/2018",
          "status": "resolved"
        },
      ]
    },
    {
      "addressId": "3",
      "address": "110 Chestnut Street",
      "tenant": "John Brown",
      "leaseDate": "07/28/2014",
      "notes": "These are some notes about 110 Chestnut Ave property.",
      "images": [ "http://www.imagelink.com/image1", "http://www.imagelink.com/image2", "http://www.imagelink.com/image3"]
    }
  ]
}

{
  "_id": "507f1f77bcf86cd799439012",
  "user": "John",
  "password": "hashed#PASSWORD",
  "email": "john@email.com",
  "role": "tenant",
  "address": "2",
  "images": [ "http://www.imagelink.com/image1", "http://www.imagelink.com/image2" ]
}

1 个答案:

答案 0 :(得分:1)

对于这种关系,我建议三个集合(斗地主,房产和租户),每个租户都有一个“landLordId”和“propertyId”。

这个“landLordId”只是landLord的ObjectId,对于属性Id也是如此。

如果您计划进行任何类型的汇总报告,或者您的房东对房产或房东与房客有多对一的映射,这将使您的生活更轻松。 (例如,给定属性的多个属性管理器)

这使得一切变得更容易/更直观,因为您只需在租户的数组中添加维护请求,租赁条款等内容,并引用任何需要。

这为能够轻松汇总任何类型的报告/查询提供了最大的灵活性。