How to create schema for embedded documents?



I was going working withThe meteor Chief - Collection 2 tutorial and noticed that there was a away to represent schema for an array of objects by using the $ symbol. My question is how do I defien schema for objects that are even deeply embedded?

Say for example collection insert is:

    "Name": "c8abd556-bfe2-44b7-a7fb-cad8cc2638d5",
        "Enable": true,
        "level1array": [{
          "default-number": 64,
          "element": true,
            "level2array": [{
                "enable": "true",
                    "level3array": [{
                            "yesno": 1 


Actually, nevermind. I figured it out after reading through the documentation for collections2.

Answer is, each embedded document must be defined independently as a SimpleSchema object, and then called in the parent document schema using type: embeddedSchema.


One small thing to add - if you don’t care about properly validating your embedded objects, look into using Simple Schema’s blackbox option.


I believe you can also use the dot syntax (and $ for arrays) instead of independent SimpleSchema objects.


Every field needs to be validated to perfection. In fact, I need to validate a subset of fields based on entries in other fields. That is what I’m pondering about now. Say for Eg, there is a drop down for Type A,B,C, selecting each of the types should auto populate certain default values, then validate certain other fields based on the type selected from the drop down.


Yes, I read further into the documentation and tried out the . and $ notation as well.