Gobliins
Gobliins

Reputation: 4026

Output / show / print Meteor Simple Schema of Entities

I have a Meteor app and generated some DB Collections which have a SimpleSchema https://github.com/aldeed/simple-schema-js attached.

Cards = new Mongo.Collection('cards');

Cards.attachSchema(new SimpleSchema({
  title: {
    type: String,
  },
  archived: {
    type: Boolean,
    autoValue() {
      if (this.isInsert && !this.isSet) {
        return false;
      }
    },
  },
  completed: {
    type: Boolean,
    autoValue() {
      if (this.isInsert && !this.isSet) {
        return false;
      }
    },
  },

And so on.

Is there a function something like: log( Cards.schema ) which outputs all the defined properties / fields and their datatypes?

Upvotes: 0

Views: 64

Answers (1)

Ankur Soni
Ankur Soni

Reputation: 6018

Yes! you can do as below at the client side, at the place you have subscribed the Cards collection.

e.g.

Template.xyz.onRendered(function(){
  console.log(Cards._c2._simpleSchema);
});

Upvotes: 0

Related Questions