pra*_*ehl 1 collections mongodb meteor meteor-collection2
我正在尝试使用Meteor Collection2构建一个集合模式.
我的集合可能的架构是:
{
items: {
id: Meteor.ObjectID
title: String,
Desc: String,
createdAt: new Date(),
creator: String,
invitedUsers: [String],
items2: [{
id: String,
pos: Number,
dur: Number,
startTime: Number,
endTime: Number,
duration: Number
items3: [{
id: String,
itemtype: String,
style: String,
items4: [{
id: String,
position: Number,
dome: String
}]
}]
}]
}
}
Run Code Online (Sandbox Code Playgroud)
那么我怎样才能最好地使用上面的嵌套模式构建Collection2集合,以及在其上执行插入,更新和删除查询的最佳方法.
更新:
现在正如Andrei Karpushonak所建议的那样,这就是我所拥有的:
Item4 = new SimpleSchema({
position: {
type: Number
},
dome: {
type: String
}
});
Item3 = new SimpleSchema({
itemtype: {
type: String
},
style: {
type: String
},
items4: {
type: [Item4]
}
});
Item2 = new SimpleSchema({
pos: {
type: Number
},
dur: {
type: Number
},
startTime: {
type: Number
},
endTime: {
type: Number
},
duration: {
type: Number
},
items3 : {
type: [Item3]
}
});
Items = new Meteor.Collection2('items', {
schema : new SimpleSchema({
title: {
type: String
},
Desc: {
type: String
},
createdAt: {
type: new Date()
},
creator: {
type: String
},
invitedUsers: {
type: [String]
},
items2: {
type: [Item2]
}
})
});
Run Code Online (Sandbox Code Playgroud)
所以现在我想弄清楚如何在这样的模式上进行插入,更新,删除操作?我是否为整个个人模式做了什么?一个例子将非常有用.
任何帮助将受到高度赞赏.
提前致谢,
Praney
您有两种选择:
创建子模式:
item2 = new SimpleSchema({
id: String,
pos: Number
})
item1 = new SimpleSchema({
id: Meteor.ObjectID,
title: String,
items2: [item2]
});
Run Code Online (Sandbox Code Playgroud)
使用点符号:
item1 = new SimpleSchema({
id: String,
pos: Number,
"item2.id": String,
"item2.pos": String
});
Run Code Online (Sandbox Code Playgroud)
我认为第一种方法更适合您的模型,因为您将对象数组作为items2的值
归档时间: |
|
查看次数: |
3176 次 |
最近记录: |