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

236
Views
TypeError deleting a file with gridfs mongoose and node.js

I am developing an application that allows uploading and downloading music. I can upload files, send them to the client... however, I have problems when it comes to deleting a bucket file...

I'am using "mongoose": "^6.2.1".

My controller, where podcastId is a ObjectId:

const connection = require('../database')
const mongoose = require('mongoose')
const Users = require('../models/Users')
const PodcastInfo = require('../models/PodcastInfo')

ctrPod.deletePodcast = async (req, res, next) => {

    try {
    
        const id = req.params.idPodInfo
        const info = await PodcastInfo.findById(id)
        const { userId, podcastId } = info
        const gridFsBucket = new mongoose.mongo.GridFSBucket(connection, {
        bucketName: 'podcasts',
        });

        gridFsBucket.delete(podcastId, (err) => {
            console.log(err)
        })
.
.
.


I get this error:

TypeError: Cannot use 'in' operator to search for 'client' in undefined
    at getTopology

The problem appears here, \node_modules\mongodb\lib\utils.js:363:23) :

function getTopology(provider) {
    if (`topology` in provider && provider.topology) {
        return provider.topology;
    }
    else if ('client' in provider.s && provider.s.client.topology) {
        return provider.s.client.topology;
    }
    else if ('db' in provider.s && provider.s.db.s.client.topology) {
        return provider.s.db.s.client.topology;
    }
    throw new error_1.MongoNotConnectedError('MongoClient must be connected to perform this operation');
}
////////////////////////
 delete(id, callback) {
        return (0, utils_1.executeLegacyOperation)((0, utils_1.getTopology)(this.s.db), _delete, [this, id, callback], {
            skipSessions: true
        });
    }
/////////////////////////////////////

What am I doing wrong?

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

0

I think the problem lies here:

 const gridFsBucket = new mongoose.mongo.GridFSBucket(connection, {
        bucketName: 'podcasts',
        });

new mongoose.mongo.GridFSBucket(db,{bucketName}) takes in a db not a connection. Try:

const gridFsBucket = new mongoose.mongo.GridFSBucket(connection.db, {
        bucketName: 'podcasts',
        });
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!