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

971
Views
MongoNetworkError: connection establishment was cancelled

I'm trying to update a database using Mongoose, but I'm getting this Network error while running my node app.

const mongoose = require('mongoose')
mongoose.connect("mongodb://localhost:27017/fruitsDB")
const fruitsSchema = new mongoose.Schema({
    name: {
        type: String,
        required: [true, "Why no Name?"]
    },
    rating: {
        type: Number,
        min: 1,
        max: 10
    },
    review: String
 });
 const Fruit = mongoose.model("Fruit", fruitsSchema)
Fruit.find(function(err, fruits){
    if(err){
        console.log(err)
    }
    
    
    else{
        mongoose.connection.close();
        
        fruits.forEach(function(fruit){
            console.log(fruit.name)
        })
    }
})
Fruit.updateOne({_id:"62b6a681eb136efde7ed17bc"}, {name: "Banana"}, function(err){
    if(err){
        console.log(err)
    }
    else{
        console.log("Successfully updated the document")
    }
})

Error: Commnad line error while running the node app

MongoNetworkError: connection establishment was cancelled
    at connectionFailureError 
    at CancellationToken.<anonymous> 
    at Object.onceWrapper (node:events:641:28)
    at CancellationToken.emit (node:events:527:28)
    at ConnectionPool.close 
    at Server.destroy 
    at destroyServer 
    at eachAsync

It's a simple Node app created using Mongoose.

about 4 years ago · Juan Pablo Isaza
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!