The example here

http://mongoosejs.com/docs/populate.html

Provides the following code

var story1 = new Story({
      title: "A man who cooked Nintendo"
    , _creator: aaron._id
  });

_creator is defined above as follows

_creator : { type: Schema.ObjectId, ref: 'Person' }

If I modify the code to the following

  var story1 = new Story({
      title: "A man who cooked Nintendo"
    , _creator: {name: 'test'}
  });

It seems to happily insert the data into MongoDB.

{ "title" : "A man who cooked Nintendo", "_creator" : { "name" : "test" }, "_id" : ObjectId("4fb7a55315c5f2de07000002"), "fans" : [ ] }

How would I catch the error before insertion? I would like to check that it is not only an ObjectId but also that it corresponds to a valid Person.

Edit
Report