I have several models:
PhoneModel, HeadphonesModel, Notebookmodel
After creating these models, I need to put them all into one generalized ProductModel model. I need to make sure that when searching in ProductModel.find(), I get a list of all models with their fields, similarly for a single search ProductModel.find({id})
// HeadphonesModel //
import mongoose, { Schema, model } from 'mongoose'
const PhoneSchema = new Schema({
name: { type: String, required: true },
type: {
type: mongoose.Schema.ObjectId,
ref: 'Type',
},
})
export default model('Phone', PhoneSchema)
// PhoneModel //
import mongoose, { Schema, model } from 'mongoose'
const Headphones = new Schema({
name: { type: String, required: true },
type: {
type: mongoose.Schema.ObjectId,
ref: 'Type',
},
})
export default model('Headphones', HeadphonesSchema)
import mongoose, { Schema, model } from 'mongoose'
const NotebookSchema = new Schema({
name: { type: String, required: true },
type: {
type: mongoose.Schema.ObjectId,
ref: 'Type',
},
})
export default model('Notebook', NotebookSchema)
import { Schema, model } from 'mongoose'
const ProductsSchema = new Schema({
// I don't know how to describe this model correctly
})
export default model('Products', ProductsSchema)