How do I initialize client for use with GridFS?

47 Views Asked by At

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

0

There are 0 best solutions below