Skip to content

Instantly share code, notes, and snippets.

@littlefyr
Created March 15, 2011 04:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save littlefyr/870289 to your computer and use it in GitHub Desktop.
Save littlefyr/870289 to your computer and use it in GitHub Desktop.
Sample validation
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/my_database');
var Schema = mongoose.Schema
, ObjectId = Schema.ObjectId;
var BlogPost = new Schema({
author : ObjectId
, title : String
, body : String
, date : Date
, comments : [Comment]
, min_commenter_age : Number
});
var Comment = new Schema({
name : { type: String, default: 'hahaha' }
, age : { type: Number, min: 18, index: true }
, bio : { type: String, match: /[a-z]/ }
, date : { type: Date, default: Date.now }
});
Comment.path( 'age' ).validate( function(v){
//How to get the minimum age from the blog post that contains this schema
}, "minimum age");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment