0

MongoDB's GridFS is not working

I'm trying to set up a gridFS project, and when I try to use "npm start", I get this error message:

const db = client.db(lcredux);
           ^
ReferenceError: client is not defined

For reference, this is the code in question:

const router = require("express").Router();
const ObjectID = require("mongodb").ObjectId;
const db = client.db(lcredux);
const bucket = new mongodb.GridFSBucket(db, { bucketName: 'songBucket' });



//GET - get all songs
//http://localhost:5002/api/v1/redux/get/all/songs
router.get("http://localhost:5002/api/v1/redux/get/all/songs", async(req,res)=>{
    if(bucket){
        const cursor = bucket.find();
        return res.status(200).send(cursor)
    }else{
        return res.status(400).send({})
    }
})

Is there something I'm missing? I've checked the official MongoDB documentation and it was not helpful

Rob Lee
  • 11
  • 1
  • Where are you declaring/defining `client`? – user20042973 Nov 17 '22 at 01:18
  • I don't have the client defined anywhere, but I don't know which dependancies I would need to initialize client – Rob Lee Nov 17 '22 at 14:51
  • Right so I don't think your issue is really related to gridfs specifically at all. Connection tutorial for node.js driver directly is [here](https://www.mongodb.com/docs/drivers/node/current/quick-start/#create-your-node.js-application), mongoose is [here](https://mongoosejs.com/docs/connections.html) – user20042973 Nov 17 '22 at 15:30

0 Answers0