我正在尝试在 2 个集合之间创建关系,但其中一个集合无法在另一个集合中引用。具体来说,我有 2 个集合:站点和内容类型。这就是它们包括的内容:
// app/lib/collections/sites.js
Sites = new Mongo.Collection('sites');
Sites.attachSchema(new SimpleSchema({
name: {
type: String,
label: "Name",
max: 100
},
client: {
type: String,
label: "Client",
max: 100
},
created: {
type: Date,
autoValue: function() {
if (this.isInsert) {
return new Date;
} else if (this.isUpsert) {
return {$setOnInsert: new Date};
} else {
this.unset(); // Prevent user from supplying their own value
}
}
}
}));
这是 ContentTypes 集合:
// app/lib/collections/content_types.js
ContentTypes = new Mongo.Collection('content_types');
ContentTypes.attachSchema(new SimpleSchema({
name: {
type: String,
label: "Name",
max: 100
},
machineName: {
type: String,
label: "Machine Name",
max: 100
},
site:{
type: Sites
},
created: {
type: Date,
autoValue: function() {
if (this.isInsert) {
return new Date;
} else if (this.isUpsert) {
return {$setOnInsert: new Date};
} else {
this.unset(); // Prevent user from supplying their own value
}
}
}
}));
当我将 Sites 引用添加到 ContentTypes 架构时,应用程序崩溃并出现以下错误:
ReferenceError:站点未在 lib/collections/content_types.js:32:11 中定义
除了this之外,我没有太多运气在 collection2 中找到关系的文档。看起来那里引用的格式应该基于这个线程工作。