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);
看来我需要重组我的数据库,如果是这样,我应该怎么做?
我需要做更多的收集吗?
我已经习惯了关系数据库,如果我知道从哪里收集所有的关系数据库,它就会开始像这样 您应该首先查看嵌入的文档与引用。这将为您提供一种方法。您应该首先查看嵌入的文档与引用。这会给你一条路。。