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

  • Home
  • SEARCH
  • 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 7018255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:01:21+00:00 2026-05-27T23:01:21+00:00

I am storing files in MongoDB. In order to retrieve them at a later

  • 0

I am storing files in MongoDB. In order to retrieve them at a later date I am recording the ObjectId associated with each file.

GridFS fs = new GridFS(Dao.getDB(), "docs");
GridFSInputFile file = fs.createFile(fAsIS);
ObjectId id = (ObjectId)file.get("_id");
file = fs.createFile(fAsIS);  //fAsIS is an InputStream
file.save();

However the value of id that is returned is always different to what is being stored.

E.g. when:

4e9845d6036400df09609b23 is stored the value returned is 4e9845d6036400df09609b22
4e98466f036400df09609b27 is stored the value returned is 4e98466f036400df09609b26
4e9848530364904b6b575003 is stored the value returned is 4e9848530364904b6b575002

The difference is only in the last digit and the difference is consistently the same: the returned value is 1 less than the stored value.

When I run my test with the stored value, the file is returned as expected. So this seems to be the issue I have to solve.

Does anyone know why this might be happening?

  • 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-27T23:01:22+00:00Added an answer on May 27, 2026 at 11:01 pm

    Probably because you call fs.createFile(fAsIs) twice

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

Sidebar

Related Questions

I have been told MongoDB uses the GridFS filesystem for storing files. However, Is
I've yet to look into storing files such as Word, Excel, etc. into MongoDB
I am storing files using GridFS and the C# official driver. I am mimic-ing
I'm storing my files in the database and need to download a file when
In my app am creating some files and storing them in cache dir .
I am using mongo for storing log files. Both mongoDB and mysql are running
We just did a move from storing all files locally to storing them on
We have a sharepoint based application that uses a custom database for storing metadata/files
For the past 5 years, my typical solution for storing uploaded files (images, videos,
Currently I am storing some mp3 files locally on a simulator using the following

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.