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

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

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 Report

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