Wednesday, 15 May 2013

node.js - Mongoose schema reference -



node.js - Mongoose schema reference -

is possible have schema reference schema within mongo?

i've got below, user in line schema user userschema

var userschema = new schema({ name: {type: string, required: true}, screen_name: {type: string, required: true, index:{unique:true}}, email: {type: string, required: true, unique:true}, created_at: {type: date, required: true, default: date} }); var lineschema = new schema({ user: [userschema], text: string, entered_at: {type: date, required: true, default: date} }); var storyschema = new schema ({ sid: {type: string, unique: true, required: true}, maxlines: {type: number, default: 10}, // max number of lines per user title: {type: string, default: 'select here set title'}, lines: [lineschema], created_at: {type: date, required: true, default: date} }); var story = db.model('story', storyschema); var user = db.model('user', userschema);

yes possible

var lineschema = new schema({ user: {type: schema.objectid, ref: 'userschema'}, text: string, entered_at: {type: date, required: true, default: date} });

also remark, why calling them lineschema , userschema ? can phone call them line , user, represent line , user after :)

node.js mongodb mongoose

No comments:

Post a Comment