Thursday, 16 March 2017

How do I reference another models value in ExpressJs?

I have a model for employee information im using in a MEAN stack and want to reference the store name they will work at in a stores model, would the following be correct?

Employees:

var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var muv = require('mongoose-unique-validator');

var schema = new Schema({
    firstName: {type: String, required: true},
    lastName: {type: String, required: true},
    empId: {type: String, required: true, unique: true},
    num: {type: String, required: true},
    job: {type: String, required: true},
    store: {type: Schema.Types.storeName, ref: 'Stores'},
});

schema.plugin(muv);

module.exports = mongoose.model('Message', schema);

Stores:

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

var schema = new Schema({
    storeName: {type: String, required: true},
    lat: {type: String, required: true},
    long: {type: String, required: true},
});

module.exports = mongoose.model('Stores', schema);



via user7629970

No comments:

Post a Comment