Meteor Cheatsheet Simple Schema
// Meteor - SimpleSchema:
Posts.attachSchema(new SimpleSchema({
someAttribute: {
type: String,
regEx: /^[a-z0-9A-Z_]{3,15}$/,
allowedValues: ['Male', 'Female'],
optional: true
},
emails: {
type: [Object],
// this must be optional if you also use other login services like facebook,
// but if you use only accounts-password, then it can be required
optional: true
},
"emails.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email
},
"emails.$.verified": {
type: Boolean
},
// Force value to be current date (on server) upon insert
// and prevent updates thereafter.
createdAt: {
type: Date,
autoValue: function() {
if (this.isInsert) {
return new Date();
} else if (this.isUpsert) {
return {$setOnInsert: new Date()};
} else {
this.unset();
}
}
},
// Force value to be current date (on server) upon update
// and don't allow it to be set upon insert.
updatedAt: {
type: Date,
autoValue: function() {
if (this.isUpdate) {
return new Date();
}
},
denyInsert: true,
optional: true
},
userId: {
type: String,
autoValue: function(){
if (this.isInsert){
return Meteor.userId();
} else if (this.isUpsert) {
return {$setOnInsert: Meteor.userId()};
} else {
this.unset();
}
}
}
}));
page revision: 0, last edited: 18 Jun 2017 01:43