Created
March 15, 2011 04:04
-
-
Save littlefyr/870289 to your computer and use it in GitHub Desktop.
Sample validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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