Astronomy Validator pkg allowing insert of empty value for required field

I am currently trying to use the Astronomy validator package to validate required fields. However, it appears that inserts are happening even if the field is empty or null. Pls see below for how I am defining the collection and then doing an insert.

Any ideas what the issue might be?

    Projects = new Mongo.Collection('projects');
    
    AstroProject = Astro.Class({
      name:'Projects',
      collection: Projects,
      fields: {
        title: {
          type: 'string',
          validator: Validators.required()
        }
      }
   }
});

MongoDB shell version: 2.6.7
connecting to: 127.0.0.1:3001/meteor
meteor:PRIMARY> db.projects.insert({});
WriteResult({ "nInserted" : 1 })
meteor:PRIMARY> db.projects.find().pretty();
{ "_id" : ObjectId("567850f74f1a8b92474f4e94") }
{
	"_id" : "hny3BSh428rmN7gZh",
	"title" : ""
}
meteor:PRIMARY> 

You insert from mongo console directly guy. Please new Astro model and save data.
Astro model doesn’t hook direct to mongo collection, so you should execute validate before save.

const post = new Post({});

if(post.validate()) {
	post.save();
} else {
	errors = post.getValidationErrors();
}
1 Like

That was the issue, thx!