I have a user schema like this:
const schema = new Schema({
name: String,
email: { type: String, trim: true, index: true, unique: true, sparse: true },
cards: {
starter : [unitSchema],
intermediate : [unitSchema],
advanced : [unitSchema]
},
});
The user schema contains specific cards for that user as arrays of starter and intermediate level etc.. right?
Then we have the unitSchema which is actually an object containing cards of the specific unit for instance we can store cards for unit 1 or cards of the unit 2 or 3 here right?
const unitSchema = new Schema(
{
unit: Number,
cards: [cardSchema]
}
);
And finally we have our cardSchema containing cards:
Please note that each card is completely unique. I mean a card can be considered as a single document in the database. it's a card containing information about performance etc of that user for the card.
const cardSchema = new Schema(
{
id: String, // like main-12-45
unit: Number, // same as unit of unitSchema
performance: [Number],
type: {
module: String,
model: String,
method: String,
},
ease: { type: Number, default: 2.5 },
currentInterval: { type: Number, default: 1 },
interact: {
pauseTimes: [Number],
recordTimes: [{ start: Number, end: Number }],
recordingStorage: { x: [Number], y: [Number] },
initialPositions: { left: String, top: String }
},
}
);
As you see so far I just nested the data and it works great. But I want to store each card in the different Model.
To be honest I don't want to, I need to! because MongoDB has limitation of 16 MB for each document and I cannot store such a big data nested inside users model.
How can I create a new model named Cards and have the same structure as above. (All the code I wrote is based on the nested structure as above any major change in the structure costs me weeks)