Go Pro Sign Up Login

Buy Now and unlock this series

yours forever

Become a Pro and unlock everything

$

24

.99

per month

- Sub-documents & Array Fields

In this Intermediate Meteor video tutorial, I talk about completing our schema by using sub-documents and array fields.Subscribe for more free tutorials https://goo.gl/6ljoFc, more Intermediate Tutorials here: https://goo.gl/11JLL8

Downloads

Become a pro to download code and videos

Comments

Christian

almost 3 years ago [edited]

The way to create an array of ingredients has changed: The new way says to add these two lines insted of [Ingredient]:

ingredients: Array, //This line sets it as an array with name 'ingredients'
'ingredients.$': Ingredient, //This line sets the type of the array

The schema at the end should be like so:

RecipeSchema = new SimpleSchema({
    name: {
        type: String,
        label: "Name"
    },
    desc: {
        type: String,
        label: "Description"
    },
    ingredients: Array,
    'ingredients.$': Ingredient,
    inMenu: {
        type: Boolean,
        defaultValue: false,
        optional: true,
        autoform: {
            type: 'hidden'
        }
    },
    author: {
        type: String,
        label: "Author",
        autoValue: function () {
            return this.userId
        },
        autoform: {
            type: 'hidden'
        }

    },
    createdAt: {
        type: Date,
        label: "Created At",
        autoValue: function () {
            return new Date()
        },
        autoform: {
            type: 'hidden'
        }
    }
});

Want to join the conversation?

Become a Pro member today!