MongoDB数据建模性能

问题描述 投票:0回答:1

我目前正试图弄清楚mongodb在性能成本和冗余方面最好的方法是构建大型文档数据模式的最佳方式。我休息的最终JSON - >应用程序很可能是它的结构。现在内部数据将不会被使用多少,这就是我将其绑定到单个文档中的原因。只有id将用作另一个集合中的引用。您认为,以关系方式吐出更好,多个集合可以将内容存储在可交付内容中,并使用引用或仅嵌入。 (因为NoSQL没有连接我虽然这种方式会加快)

当前在节点app上使用mongoose The Schema:

projectSchema = new Schema({
name: {
    type: String,
    required: true,
    minlength: 3,
    maxlength: 50
},
companyId: {
    type: mongoose.Types.ObjectId,
    ref: 'companies',
    required: true
},
deleted: {
    type: Number,
    enum: [0, 1],
    default: 0
},
predictedStartDate: {
    type: Date,
    default: ""
},
predictedEndDate: {
    type: Date,
    default: ""
},
realStartDate: {
    type: Date,
    default: ""
},
realEndDate: {
    type: Date,
    default: ""
},
//not final version
riskRegister: [{
    name: String,
    wpId: {
        type: mongoose.Types.ObjectId,
        ref: 'projects.deliverables.workPackages.id',
        required: true
    },
    probability: String,
    impact: String,
    riskOwner: String,
    response: String,
    duration: String,
    trigger: String,
    status: String,
    plannedTimming: String
}],
deliverables: [{
    body: String,
    workPackages: [{
        body: String,
        activities: [{
            body: String,
            tasks: [{
               content: String,
               properties: [{
                   dependecies: Array,
                   risk: {
                       type: Number,
                       enum: [0,1],
                       required: true
                   },
                   estimatedTime: {
                       type: Number,
                       required: true
                   },
                   realTime: {
                      required: true,
                      default: 0,
                      type: Number 
                   },
                   responsible: {
                       id: {
                           type: Number,
                           default: -1
                       },
                       type: {
                           type: String,
                           enum: [0, 1], //0 - user, 1 - team
                           default: -1
                       }
                   },
                   materialCosts: {
                       type: Number,
                       default: 0
                   },
                   status: {
                       type: Number,
                       default: 0
                   },
                   approval: {
                       type: Number,
                       default: 0
                   },
                   startDate: {
                       type: Date,
                       default: ""
                   },
                   finishDate: {
                       type: Date,
                       default: ""
                   },
                   endDate: {
                       type: Date,
                       default: ""
                   },
                   userStartDate: {
                        type: Date,
                        default: ""
                   },
                   endStartDate: {
                        type: Date,
                        default: ""
                   },
                   taskNum: {
                       type: Number,
                       required: true
                   },
                   lessonsLearn: {
                    insertedAt: {
                        type: Date,
                        default: Date.now
                    },
                    creatorId: {
                        type: mongoose.Types.ObjectId,
                        ref: 'users',
                        required: true
                    },
                    situation: {
                        type: String,
                        required: true
                    },
                    solution: {
                        type: String,
                        required: true
                    },
                    attachments: Array
                   }
               }] 
            }]
        }]
    }]
}]

})

javascript mongodb performance nosql
1个回答
1
投票

我要提出的唯一问题是关于可交付成果。如果将来有一个用例来对workPackage上的活动或任务进行一些CRUD操作,那么mongodb位置运算符$不支持inner arrays,因此你将被迫提取所有可交付成果并在内存中迭代所有且仅更新可交付成果后。我的兴趣是只支持对象的第一级数组。内部对象应该在单独的集合(活动和任务)中进行模块化。在mongodb的最新版本中,您现在可以支持transactions,因此您可以对数据库的操作实现ACID,因此可以以原子方式处理所有这些信息。

© www.soinside.com 2019 - 2024. All rights reserved.