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

217
Views
saving array type value inside mongodb schema using node js

I am trying to put array data inside my schema but its not showing in my mongodb Schema

ownerSchema.js

var ownerSchema = Schema({
    ownerId   : String,
    fname     : String,
    lname     : String,
    shopPlace : { 
                  type: Schema.Types.ObjectId,
                  ref: 'Shop'
                },
    shopType    String
});
var Owner = mongoose.model('Owner', ownerSchema);

shopSchema.js

var shopSchema = Schema({
    _id       : String,
    shopName  : String,
    location  : String,
    startDate : Date,
    endDate   : Date
});
var Shop  = mongoose.model('Shop', shopSchema);

as I am sending array format data inside shopType but its not showing any data inside schema

as I am sending this from postman my format look like this

{
 "ownerId"   : "Own001",
 "fname"     : "Tom",
 "lname"     : "jerry",
 "shopPlace" : {
                 "shopName" : "Juice Center",
                 "location" : "Mumbai",
               },
 "shopType"  : ["Juice","vegetables"]
}

but when I am sending this data only ownerId, fname,lname, shopPlace showing inside schema my shopType data can't be seen

const addTask = async (req, res) => {
  const { shopName, location } = req.body.shopPlace;
  const shopDetails = new Shop({
      shopName,
      location,
    });
    await shopDetails.save();

    const { ownerId, fname, lname, shopType } = req.body;
    const ownerDetail = new Owner({
      ownerId,
      fname,
      lname,
      shopType,
      shopPlace: shopDetail._id,
    });
    await shopDetail.save();
};

I want to store shopType in array format but Its even not showing inside my schema

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

change your schema like it

var ownerSchema = Schema({
    ownerId   : String,
    fname     : String,
    lname     : String,
    shopPlace : { 
                  type: Schema.Types.ObjectId,
                  ref: 'Shop'
                },
    shopType :   [{
    type: String
}]
});
var Owner = mongoose.model('Owner', ownerSchema);
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!