Skip to content


Subversion checkout URL

You can clone with
Download ZIP


strict: true for embedded documents #717

timfinity opened this Issue · 4 comments

5 participants


I've noticed that strict: true doesn't work for embedded documents. I wasn't sure if this was by design or not.

A quick example:

var Comments = new Schema({
    title     : String
  , body      : String
  , date      : Date
}, {strict: true});

var BlogPost = new Schema({
  , title     : String
  , body      : String
  , comments  : [Comments]
}, {strict: true});

var Post = mongoose.model('BlogPost', BlogPost);

var post = new Post();

post.title = 'Saves';
post.fake = 'Doesnt save';

  title: 'Saves',
  fake: 'Shouldnt save but does'


well that sucks

@aheckmann aheckmann closed this in 248710c

An important note:

You have to put child schema before the parent schema for strict mode to work properly with subdocuments. For this example, that means putting the Comments declaration before the BlogPost declaration. If you don't, strict mode will not work for subdocuments.

Hopefully this will help people avoid the same problem I just ran into. Perhaps a note in the documentation would be helpful? In general, javascript doesn't care what order you declare functions and classes, so I found this behavior a little surprising.


So it seems mongoose is setting strict mode to true for all but for some reason it is failing to enforce it when it comes to subdocuments.

Even when I put child schema before parent schema it is not working for me, I guess I will post an issue with an example.


@offminded please do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.