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

179
Views
NextJS array mapping for POST request

I am learning Next.js currently, and I have a question.

I have this data as a req.body:

{
    "name": "Name Here",
    "phone": [
        {
            "phonetype": "Work",
            "phonenumber": "PhoneNumber1"
        },
        {
            "phonetype": "Home",
            "phonenumber": "PhoneNumber2"
        }
    ],
    "city": "CityHere"
}

And I am trying to create a new Customer in the database. Below is my POST:

case 'POST':
    try{
        const customer = req.body;
        const newCustomer = new Customer({
            name: customer.name,
            //phone: HOW TO I HANDLE THIS ARRAY?
            city: customer.city,
        });

        const createdCustomer = await Customer.create(newCustomer);
                
        res.status(201).json({success: true, data: createdCustomer});
    } catch (error) {
        res.status(400).json({success: false, data: "Error Creating Customer"});
    }
    break;

How do I go about submitting it to the database (using Mongoose)?

Schema below:

const CustomerSchema = new Schema({
    name: {
        type: String,
        required: true,
        trim: true,
    },
    phone: {
        phonetype: {
            type: String,
        },
        phonenumber: {
            type: String,
        },
    },
    city: {
        type: String,
        required: true,
        trim: true,
    }
})
about 4 years ago · Juan Pablo Isaza
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!