Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6219787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:50:42+00:00 2026-05-24T07:50:42+00:00

I have a function saving a file to gridfs. It somehow stopped working sporadically

  • 0

I have a function saving a file to gridfs. It somehow stopped working sporadically after a refactor and I’ve spent over 2 hours staring blankly at it. I swear it’s roughly the same as it was. I seem to remember it not working at first before I added close, then it started working, but it could be the insomnia. Essentially the issue is the db.fs.files collection doesn’t have any records, but chunks are getting added to db.fs.chunks.

data is a buffer loaded from disk via fs.readFile()

 31    var gs = new mongodb.GridStore(this.db, filename, "w", {
 32        "chunk_size": 1024*4,
 33        metadata: {
 34          hashpath:gridfs_name,
 35          hash:hash,
 36          name: name
 39        }
 40    });
 41    gs.open(function(err,store) {
 42       gs.write(data,function(err,chunk) {
 43          //cb(err,hash,chunk);
 44          //self.close();
 45       });
 46    });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:50:42+00:00Added an answer on May 24, 2026 at 7:50 am

    There are a couple of solutions. You can use writeBuffer, writeFile or the new simple grid class. Under is your example adjusted for the fact of using a buffer instance.

    // You can use an object id as well as filename now
    var gs = new mongodb.GridStore(this.db, filename, "w", {
      "chunk_size": 1024*4,
      metadata: {
        hashpath:gridfs_name,
        hash:hash,
        name: name
      }
    });
    
    gs.open(function(err,store) {
      // Write data and automatically close on finished write
      gs.writeBuffer(data, true, function(err,chunk) {
        // Each file has an md5 in the file structure
        cb(err,hash,chunk);
      });
    });
    

    In general the best place to start are the tests that cover a wide usage profile for the gridfs classes. Look at.

    https://github.com/christkv/node-mongodb-native/tree/master/test/gridstore

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Java code I have function that gets file from the client in
I have a small question. I'm writing a loading/saving function for getting plain geometry
I'm saving NumPy arrays using numpy.save function. I want other developers to have capability
I have this code to get the caller of my function's file name, line
I have uploaded some images using uploadify and saving the original file in uploads
i have function public Menu Details(int? id) { return _dataContext.Menu.Include(ChildMenu).FirstOrDefault(m => m.MenuId == id);
I have function: char *zap(char *ar) { char pie[100] = INSERT INTO test (nazwa,
I have function getCartItems in cart.js and I want to call that function in
If I have function names stored as strings in a Hashtable. Is there a
let say i have function like below function doSomethingNow(){ callSomethingInFutureNotExistNow(); } at the moment

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.