I have two schemas, a course and a section schema. I want to have a array of section title references from the section schema into the course schema instead of an array of section objectIds’ like that in the code. I have tried serveral options such a ‘ref’ and 'boundTo 'but none of these two methods worked. Note that the schemas are in two different file
// Mongoose model class for Courses
const mongoose = require("mongoose");
const { Schema } = mongoose;
// Class description
const courseSchema = new Schema({
title: String,
description: String,
_user: { type: Schema.Types.ObjectId, ref: "User" },
dateCreated: Date,
dateUpdated: Date,
coverImg: String,
category: String,
published: Boolean,
sections: [{ type: Schema.Types.ObjectId, subRef: "Components" }],
});
const CourseModel = mongoose.model("courses", courseSchema); // Create new collection called courses, using the courseScema
module.exports = { CourseModel }
// Mongoose model class for Courses
const mongoose = require("mongoose");
const { Schema } = mongoose;
// Class description
const sectionSchema = new Schema({
title: String,
description: String,
dateCreated: Date,
dateUpdated: Date,
components: [{ type: Schema.Types.ObjectId, ref: "Component" }],
});
const SectionModel = mongoose.model("sections", sectionSchema);
module.exports = { SectionModel }