【发布时间】:2016-04-03 23:25:24
【问题描述】:
我已经使用简单模式设置了这样的集合:
SubLinkSchema = new SimpleSchema({
name: {
type: String,
label: 'Link Name',
unique: false
},
link: {
type: String,
regEx: SimpleSchema.RegEx.Url,
label: 'Custom Link',
optional: true,
autoform: {
class: 'sub-custom-link'
}
}
});
LinkSchema = new SimpleSchema({
name: {
type: String,
label: 'Link Name',
unique: false
},
link: {
type: String,
regEx: SimpleSchema.RegEx.Url,
label: 'Custom Link',
optional: true,
autoform: {
class: 'main-custom-link'
}
},
subLinks: {
optional: true,
label: 'Sub Links',
unique: false,
type: [SubLinkSchema]
}
});
在这里,问题是,子链接没有获得 ID。没有 id 很难更新它们。那么,如何为每个子链接(嵌入文档)生成唯一 ID?
【问题讨论】:
-
查找
Random.Id()。 -
@Kyll 会不会是独一无二的?
-
我同意MrE,应该使用SimpleSchema的“autoValue”,但是看看这个包:atmospherejs.com/mantarayar/shortid它非常好用,ids看起来像mongo ids。
标签: meteor meteor-autoform meteor-collection2 simple-schema