Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

238
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda