How to use the GridFSBucket function from mongodb

Find comprehensive JavaScript mongodb.GridFSBucket code examples handpicked from public code repositorys.

262
263
264
265
266
267
268
269
270
271
// Remove the post with the provided postId
const result = await Post.deleteOne({ _id: postId });

if (result.deletedCount === 1) {
  // Delete the image using GridFSBucket
  const bucket = new GridFSBucket(mongoose.connection.db, {
    bucketName: "posts",
  });

  // Find the image file in the posts.files collection
fork icon1
star icon3
watch icon0

+ 2 other calls in file

358
359
360
361
362
363
364
365
366
367
368
router.get("/profile/avatar/:filename", async (req, res) => {
  try {
    // connect to mongo upload collection bucket,
    // here bucket we mean we have "upload.chunks" and "uploads.files"
    // so it actually have two collection but the root is upload which is the bucket
    const bucket = new GridFSBucket(conn.db, { bucketName: "accounts" });


    //get filename from URL params
    const filename = req.params.filename;

fork icon1
star icon3
watch icon0

+ 2 other calls in file

224
225
226
227
228
229
230
231
232
233
const id = req.query.id;
uri = process.env.MANGO_DB_CONNECTION_STRING;
const client = new MongoClient(uri);
try {
  const database = client.db('edds');
  const bucket = new GridFSBucket(database, {
    bucketName: 'photos',
  });

  let downloadStream = bucket.openDownloadStreamByName(id);
fork icon0
star icon0
watch icon1

+ 4 other calls in file

10
11
12
13
14
15
16
17
18
19
20
21
const upload = multer();




router.post('/uploadProfileImage', upload.single('file'), async(req, res) => { 
  const db = mongoose.connection.db;
  const bucket = new mongodb.GridFSBucket(db, { bucketName: 'profilePicture' });
  if(req.file===undefined){
    console.log("undefined file")
  }
  else {
fork icon0
star icon0
watch icon1

+ 7 other calls in file