Dynamic References in schema

156 views
Skip to first unread message

manikanta reddy

unread,
Jul 19, 2016, 6:57:19 AM7/19/16
to Mongoose Node.JS ODM
How can i create dynamic references ? i am stuck with this for days

var mongoose = require('mongoose'),
    Schema = mongoose.Schema;

var CommentSchema = new Schema({
    message: { type: String, required: true },
    documentId: { type: Schema.Types.ObjectId, ref:['doc1','doc2' ]] }, // how can i  solve this using dynamic references 
    user: { type: Schema.Types.ObjectId, ref: 'User', required: true }
}, {
    // createdAt,updatedAt fields are automatically added into records
    timestamps: true
});

ex: documentId: { type: Schema.Types.ObjectId, ref:['doc1','doc2' ]] },

man...@volteo.com

unread,
Aug 13, 2016, 1:58:32 PM8/13/16
to Mongoose Node.JS ODM
Reply all
Reply to author
Forward
0 new messages