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 7774899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:29:39+00:00 2026-06-01T17:29:39+00:00

Getting node.js and gridfs to play nice is not easy. Of all the things

  • 0

Getting node.js and gridfs to play nice is not easy. Of all the things I tried, I settled on this being as close as I could get with limited knowledge and what I understand the current supported functions will allow.

(below in coffee, use http://js2coffee.org/ to get to the js and vice versa)

util = require("util")
mongodb = require("mongodb")
GridStore = mongodb.GridStore
parse = (options) ->
  opts = {}
  opts = options[0]  if options.length > 0
  opts.metadata = {}  unless opts.metadata
  opts

db = new Db("local", new Server("127.0.0.1", 27017,
  auto_reconnect: false
  poolSize: 1
),
  native_parser: false
)
db.open()
putFile = (path, name, options, fn) ->
  options = parse(options)
  options.metadata.filename = name
  new GridStore(db, name, "w", options).open (err, file) ->
    return fn(err)  if err
    file.writeFile path, (err, fn) ->
      file.close()

opts = content_type: "plain/text"
myfileupload = putFile("myfile.txt", "known_hosts", opts)
db.close()

Strangely however, using apt-get install mongodb-10gen on Ubuntu 11.10, my file is not saved. And there are no error messages to help me understand why.

I am close to believing that everything I read about gridfs and nodejs is all just a cruel joke, and I am never going to see this work. Please help.

  • 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-06-01T17:29:41+00:00Added an answer on June 1, 2026 at 5:29 pm

    I suspect an async issue. You’re calling db.close() immediately after the call to putFile, so db.close() is running before the GridStore‘s open callback fires, right? Seems like it could be a problem. Try moving db.close() into the same callback as file.close().

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

Sidebar

Related Questions

I am having trouble getting the node-mongodb-native drivers to play nice. I've installed everything,
First day at programming in Node today. I've been getting along nicely all day
I'm getting sometimes the error "Text node cannot appear in this state" in my
I'm getting this error when I try and install node on my new mac
When I'm getting this page http://booking.airasia.com/css/AKBase/Cultures/en-GB/far-min.css with node's http , the toString method gives
I want to get the user roles Just like getting node types using this
I just started getting into node.js and followed this great tutorial on node.js at
Getting this error cross compiling node.js for optware (slug) on Ubuntu 11.10. /optware/cs05q1armel/builds/node/build/default/libv8.a(api.o): Relocations
I am getting process.nextTick error on this very basic example of node.js. Can someone
I am querying document in XOM, getting a Node, and then querying this Node

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.