在 SimpleSchema 中使用 Meteor.ObjectID 作为类型

Using Meteor.ObjectID as a type in SimpleSchema

我有两个使用 SimpleSchema 的模式 - 比如说 Schema1 和 Schema2。我想在 Schema2 中引用 Schema1 的内部 ObjectId (_id)。我该怎么做?

Schema1 看起来像这样:

Schema1 = new SimpleSchema({
    aitem: {
        type: String
    },
    anitem: {
        type: String
    }
});

Schema2 看起来像这样:

Schema2 = new SimpleSchema({
    aaitem: {
        type: String
    },
    aanitem: {
        type: String
    },
    refItem: {
        type: Mongo.ObjectID
    }
});

当我尝试在 Meteor 中插入时,它说无法验证 ObjectID

Mongo.ObjectId 不是可接受的验证器。内部 _id 值是 JavaScript 的字符串,因此您可以这样做:type: String,这应该有效。

使用:Mongo.Collection.ObjectID