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

218
Vistas
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 Respuestas
Responde la pregunta

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 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