Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

293
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!