Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

138
Vistas
Create another Model for storing nested data

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)

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda