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

313
Views
mongoose: save is not a function

Given a user model:

import { model, Schema } from 'mongoose'

export interface User {
  email: string
}

const userSchema = new Schema<User>(
  {
    email: {
      type: String,
      required: true,
    },
  },
)

export const UserModel = model<User>('User', userSchema)

I'm trying to save it as so:

// inside an async function
const newUser: HydratedDocument<User> = new UserModel({
  email: 'aaa@aaa.com',
})

console.log(newUser)

await newUser.save()

Which results in newUser.save is not a function. What am I missing? Also, here is the output of the `console.log(newUser)

Also, here is the output of the `console.log(newUser)

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

0

My stupid mistake: I was calling everything on the fronted. Solution is as easy as moving relevant db calls to the endpoint.

about 4 years ago · Juan Pablo Isaza Report

0

You will need to also define a model, change your schema definition to this:

first create model from Schema :

 var UserModel = mongoose.model('User', User);

then create object out of User model

 var user = new UserModel(req.body)

then call

 user.save(function(){});

check documentation http://mongoosejs.com/docs/api.html#model_Model-save

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!