Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

141
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda