LearnBoost/mongoose — Issue #722: embedded doc - no validation 
Author: mmukhin
Created: 2012-02-08 08:42:06+00:00
State: open

I'm assuming this was not intended and that I dont have errors :)

var Person = new Schema({
first_name : { type: String, required: true, trim: true }
, last_name : { type: String, required: true, trim: true }
, username : { type: String, required: true, trim: true, unique: true }
, hobbies : [Hobby]
, shoe_size : Number
, eye_color : String
});

function sampleval(v){
return v.length < 3;
}
var Hobby = new Schema({
name : { type: String, required: true, trim: true, unique: true, validate: [sampleval] }
});

None of the Hobby validations work (unique, required (if blank string after trimming), sampleval)...

Person.findOne({ username: req.params.username }, function(error, person){
if(error){
res.json(error);
}
else if(person == null){
res.json('no such user!')
}
else{
person.hobbies.push({ name: req.params.hobby });
person.save( function(error, data){
if(error){
res.json(error);
}
else{
res.json(data);
}
});
}
});