How to define a foreign key using mongoose in nodeJS?
Here is an example of schema that I'm trying to make, where id_def needs to refer to the primary key of def table which is id
var abcSchema = mongoose.Schema({
name: String,
id_def: Number // foreign key
});
Thanks in advance!
Try this:
var abcSchema = mongoose.Schema({
name: String,
_def: { type: mongoose.Schema.Types.ObjectId, ref: 'def' }
});