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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:18:29+00:00 2026-06-06T05:18:29+00:00

When I am writing a file into GridFS using grid.put(), which has the same

  • 0

When I am writing a file into GridFS using grid.put(), which has the same filename as a file stored before, the first file is going to be overwritten. Is it actually true that the same filename can only exist once in the database or am I doing something wrong?

My code looks like this:

var mongo = require('mongodb'),
  Server = mongo.Server,
  Db = mongo.Db,
  Grid = mongo.Grid;
  server = new Server('localhost', 27017, {auto_reconnect: true});
  db = new Db('mydb', server);

db.open(function(err, db) {
  var buffer = new Buffer("This is the first sample text");
  grid.put(buffer, {metadata:{}, filename: "test.txt", content_type: 'text'}, function(err, fileInfo) {
    buffer = new Buffer("This is the second sample text");
    // now this overwrites the first one...
    grid.put(buffer, {metadata:{}, filename: "test.txt", content_type: 'text'}, function(err, fileInfo) {
    });
  });
});

I thought that the file is specified unique by the ._id ObjectId and not by the filename. Am I wrong?

Thanks for your 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-06T05:18:32+00:00Added an answer on June 6, 2026 at 5:18 am

    Per the GridFS spec the files are indexed by _id. The filename is part of the metadata, and does not have to be unique. If you put something with the same filename twice, you should be able to confirm both files exist by using mongofiles list from a command line.

    What version of the MongoDB Node.js driver are you using? It looks like there was a driver bug corrected several months ago: Cannot save files with the same file name to GridFS.

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

Sidebar

Related Questions

I am writing a XML file into a HTML file using JavaScript. Here is
I am having trouble writing my file into the plist after going through many
I'm writing a program that passes data from a file into an array, but
I'm writing a file on a network drive into a new folder. string directory=@\\dir\test\
I am writing some code to add file attachments into an application I am
I am writing an XSLT file to translate an XML document into an XHTML
When writing PTX in a separate file, a kernel parameter can be loaded into
I'm writing an Ant script to package a project into a WAR file. The
I'm writing a php script to export MySQL database rows into a .txt file
I am writing the below structure in to the file using Binary Writer. File

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.