Smart hasMany relationship in mongoDB
Smart hasMany relationship in mongoDB
Models definition
// This model was generated by Lumber. However, you remain in control of your models.
// Learn how here: <https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models>
const mongoose = require('mongoose');
// This section contains the properties of your model, mapped to your collection's properties.
// Learn more here: <https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model>
const schema = mongoose.Schema(
{
avatar_link: String,
client: { type: mongoose.Schema.Types.ObjectId, ref: 'client' },
date_added: Date,
email: String,
first_name: String,
last_name: String,
user_type: String,
},
{
timestamps: false,
}
);
module.exports = mongoose.model('user', schema, 'user');Declaration of the relationship
Implementation of the get route for the relationship
Last updated
Was this helpful?