Using Meteor.ObjectID as a type in SimpleSchema

4.4k Views Asked by At

I have two Schemas using SimpleSchema - say Schema1 and Schema2. I want to reference the internal ObjectId (_id) from Schema1 in Schema2. How do I go about doing this?

Schema1 looks like this:

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

Schema2 looks like this:

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

When I try an insert in Meteor it says cannot validate ObjectID

2

There are 2 best solutions below

1
On BEST ANSWER

Mongo.ObjectId is not an acceptable validator. The internal _id values are strings to JavaScript, so you can do: type: String and that should work.

0
On

Use: Mongo.Collection.ObjectID