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

102
Views
mongoose insertOne node.js failing on insert

I have this model, defining my mongoose schema and such:

const servicesSchema = new mongoose.Schema({
    cnum: {
        type: String,
        required: true,
        unique: true,
        trim: true
    },
    location: {
        type: String,
        required: true,
        trim: true
    },
    name: {
        type: String,
        required: true,
        trim: true
    }
}, {
    timestamps: true
})

//force collection name
servicesSchema.set('collection', 'services');

servicesSchema.methods.toJSON = function () {
    const servicesObject = this.toObject()

    return servicesObject
}

const Services = mongoose.model('Services', servicesSchema)

module.exports = Services

then, in my route, I have this:

const ServicesModel = require('../model/services')
app.post('/updateServices', (req, res) => {
    //defining variables passed through from front-end
    var siteLocation = req.body.siteLocation;
    var Services = req.body.Services;
    var date = req.body.date;
    var cnum = req.body.cnum;
    console.log(siteLocation, Services, date, cnum)

  
        //defining parameters to insert into document
        const doc = {
            siteLocation: siteLocation,
            Services: Services,
            date: date,
            cnum: cnum
        };

        console.log(doc)
        //actually inserting document into collection.
        ServicesModel.insertOne(doc)

        //redirecting to set page or function
        res.status(200).send("success")
})

but, when I try to insert (the insertone), it tells me in my console that TypeError: ServicesModel.insertOne is not a function.

I am wondering what the problem is. keep in mind, I have never used mongoose before and never set it up like this, so apologies in advance. thanks for the help

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

0

Figured it out.

Mongoose doesn't support insertOne

you must use create

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!