Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.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
Mongodb 我如何重组我的数据库?_Mongodb_Mongoose Schema - Fatal编程技术网

Mongodb 我如何重组我的数据库?

Mongodb 我如何重组我的数据库?,mongodb,mongoose-schema,Mongodb,Mongoose Schema,我有一个包含嵌入式文档的集合。当在文档中更新文档时,这种方法工作得很好,但是当我必须在文档中的文档中更新文档时,就会出现问题。为了实现这一点,我需要使用双精度“$”,这是不可能的。 这项工作: {$push: { "progress.$.exercise":{ "exercise":exercise } } 这就是问题所在: {$push: { "progress.$.exercise.$.workout":{

我有一个包含嵌入式文档的集合。当在文档中更新文档时,这种方法工作得很好,但是当我必须在文档中的文档中更新文档时,就会出现问题。为了实现这一点,我需要使用双精度“$”,这是不可能的。 这项工作:

{$push: {
        "progress.$.exercise":{
            "exercise":exercise
        }
}
这就是问题所在:

{$push: {
        "progress.$.exercise.$.workout":{
            "_set":_set, 
            "reps":reps,
            "weight":weight
        }
    }
因为dobbel$无法完成,而且似乎没有办法(我可以找到)使用elemMatch完成。我只能得出结论,我构建数据库的方式是错误的

以下是我的模式:

var Workout = new mongoose.Schema({
    _set : {
        type: String
    },
    reps: {
        type: String
    },
    weight: {
        type: String
    }
});


var Exercise = new mongoose.Schema({
    exerciseName : {
        type: String
    },
    workout : [Workout]
});


var Progress = new mongoose.Schema({
    date : {
        type: String
    },
    name : {
        type: String
    },
    exercise : [Exercise]
});


var UserSchema = mongoose.Schema({
    username: {
        type: String,
        index:true
    },
    password: {
        type: String
    },
    email: {
        type: String
    },
    name: {
        type: String
    },
    progress : [Progress]

});


var User = module.exports = mongoose.model('User', UserSchema);
看来我需要重组我的数据库,如果是这样,我应该怎么做? 我需要做更多的收集吗?
我已经习惯了关系数据库,如果我知道从哪里收集所有的关系数据库,它就会开始像这样

您应该首先查看嵌入的文档与引用。这将为您提供一种方法。您应该首先查看嵌入的文档与引用。这会给你一条路。。