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

193
Vistas
Model Imported. But still company.save() not a function

I'm using .find to locate the right company and then adding values to it.....did a console.log(company)is working properly.

But when trying to save it....I get company.save() is not a function. I'm new to mongoose and programming. Can't figure out what I'm doing wrong.

const { Company } = require('../models/company');

 const company = await Company.find({
                userAdmin: `${data.object.metadata.userId}`
            });

            company[0].customerId = data.object.customer;
            company[0].postNumber = data.object.metadata.postNumber;
            company[0].accountStatus = data.object.metadata.accountStatus;

            try {
                await company.save();
            } catch (ex) {
                console.log(ex.message);
                for (field in ex.errors) console.log(ex.errors[field].message);
            }

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

.find() on a mongoose model returns an array of documents, not just one.

An array won't have the .find() funtion on it; only the documents themselves inside it will.

If you're only looking for a single document, use .findOne() instead.

over 4 years ago · Santiago Trujillo Denunciar

0

Cause I company have multiple document in it . And you just modify one and save one too so you should try company[0].save()

over 4 years ago · Santiago Trujillo 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