[mongoose] Default value for array

1,952 views
Skip to first unread message

Mario

unread,
Jan 16, 2012, 10:49:34 AM1/16/12
to Mongoose Node.JS ORM
I have the following mongoose schema:

var Document = new Schema({
name : {type: String, default: 'Untitled'}
});

var User = new Schema({
name : {type: String, default: 'Erik'},
docs : [Document],
created : {type: Date, 'default': Date.now},
lastModified : {type: Date, 'default': Date.now}
});

Is is possible to make an one document by default in 'docs' array when
creating an new user?
I mean when I do User.create() I want to get the following document in
MongoDB

{
_id: ObjectId(...),
name: Erik,
docs: [
{
name: 'Untitled'
}
],
created: 2012-01-15,
lastModified:2012-01-15
}

Aaron Heckmann

unread,
Jan 27, 2012, 2:23:12 PM1/27/12
to mongoo...@googlegroups.com
have you tried

docs: { type: [Document], default: PutYourDocHere }


On Mon, Jan 16, 2012 at 10:49 AM, Mario <likejav...@gmail.com> wrote:
docs          : [Document],



--
Aaron


Reply all
Reply to author
Forward
0 new messages