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

292
Vistas
How do I add/reference objectID,name,phone etc from another collection(schema) to a new one?

I'm trying to create a simple form where the user will customize their cake and when the data save in database the user's info will be saved there also automatically. how do I do that?

this is just like any order model from e-commerce websites but I can't add the user's data in the order model automatically.

the mongoose schema I've created is like this.

const mongoose = require('mongoose');
const { required } = require('nodemon/lib/config');
const Schema=mongoose.Schema;

const customCakeSchema=Schema({
    user:{
        type:Schema.Types.ObjectId,
        ref:'saved_user'
    },
    // order_By:{
    //     type:Schema.Types.ObjectId,
    //     ref:'saved_user'
    // },
    // phone:{
    //     type:Schema.Types.ObjectId,
    //     ref:'saved_user'
    // },
    // address:{
    //     type:Schema.Types.ObjectId,
    //     ref:'saved_user'
    // },
    weight:{
        type:String,
        required:true
    },
    flavour:{
        type:String,
        required:true
    },
    shape:{
        type:String,
        required:true
    },
    layers:{
        type:Number,
        required:true
    },
    sponge:{
        type:String,
        required:true
    },
    cakeType:{
        type:String,
        required:true
    },
    creamLevel:{
        type:String,
        required:true
    },
    fondantLevel:{
        type:String,
        required:true
    },
    fondantCreamLevel:{
        type:String,
        required:true
    },
    paintCake:{
        type:String,
        required:true
    },
    fillings:{
        type:String,
        required:true
    },
    effects:{
        type:String,
        required:true
    },
    writingOnCake:{
        type:String,
        required:true
    },
    status:{
        type:String,
        default:'pending'
    },
    payment:{
        type : Boolean,
        default: false
    },
    delivered: {
        type : Boolean,
        default: false
    },
    createAt :{
        type : Date,
        default : Date.now
    }
});

const customCakeModel=mongoose.model('custom_cake',customCakeSchema);
module.exports=customCakeModel;```
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

const example = new custom_cake({
   user:user._id,  //<-- Need to save user id with the new data
})

To get referenced collections from the custom_cake you need to populate

custom_cake.find().populate('user').exec()
about 4 years ago · Juan Pablo Isaza Denunciar
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