Why was mongoose designed in this way? Why was mongoose designed in this way? mongoose mongoose

Why was mongoose designed in this way?


It's designed that way so that you can define a schema for subdocuments, which do not map to distinct models. Keep in mind that a there is a one-to-one relation between collections and models.

From the Mongoose website:

var Comments = new Schema({    title     : String  , body      : String  , date      : Date});var BlogPost = new Schema({    author    : ObjectId  , title     : String  , body      : String  , buf       : Buffer  , date      : Date  , comments  : [Comments]  , meta      : {      votes : Number    , favs  : Number  }});var Post = mongoose.model('BlogPost', BlogPost);


Yeah sometimes I split the Schema's up into separate files and do this kind of thing.

// db.js var ArticleSchema = require("./ArticleSchema");mongoose.Model("Article", ArticleSchema);

It's only really useful when you have a bunch of static and other methods on models and the main model file gets messy.