-
Notifications
You must be signed in to change notification settings - Fork 1
Schema fields' naming convention for mongoose ODM
fredchu edited this page May 15, 2012
·
1 revision
// for example
PostSchema = new Schema({
title : { type : String },
content : { type : String },
is_writable : { type : String },
is_published : { type : Boolean }
});
- Fields to embed structural documents
// for example
var PostSchema = new Schema({
title : { type : String },
content : { type : String },
user : UserSchema,
comments : [ CommentSchema ]
});
- Fields to populate related objects
// for example
var PostSchema = new Schema({
title : { type : String },
content : { type : String },
user : { type : ObjectId },
comments : [{ type : ObjectId}]
});
- Fields to cache corresponding objects
// for example
var PostSchema = new Schema({
title : { type : String },
content : { type : String },
as_user : { type : Schema.Types.Mixed },
as_comments : [{ type : Schema.Types.Mixed}]
});
Note that it seems that in mongoose _plural name to a corresponding model has special usage internally, so it is not a good idea to use _comments as the field name to refer to comments in a post.