Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

237
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda