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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:05:16+00:00 2026-05-31T21:05:16+00:00

I am storing files using GridFS and the C# official driver. I am mimic-ing

  • 0

I am storing files using GridFS and the C# official driver.
I am mimic-ing a folder structure and am storing the full directory path in the metadata (i.e. /folder1/subfolder1 ). I am also storing multiple versions of a file using the built-in versioning feature of MongoDB.
This allows me to query for the files in a specific folder using :

var filesQuery = Query.EQ("metadata.ParentPath", myParentPath);
var filesMongo = MongoDatabase.GridFS.Find(filesQuery);

My problem is that this query returns all the files, including the old ones.
How can I insert the version parameter and return only the last uploaded files (as used in the FindOne method of the C# driver)?
I don’t know how to include it in the query (“version” doesn’t work as it’s handled with the upload date internally as far as I know).

Thanks !

  • 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-31T21:05:18+00:00Added an answer on May 31, 2026 at 9:05 pm

    I can’t think of any way you could write the query to return the newest version of each file in your ParentPath. If you were just returning a single file you could sort by the uploadDate descending and take just the first one (just like the driver does), but that trick doesn’t work when you are returning all the files in the directory.

    You could write a map/reduce job to do this, but that’s probably overkill.

    You could also add another boolean (e.g. metadata.isCurrentVersion) to your metadata to flag the current version of each file. It would be up to you to clear the flag on all older versions each time you upload a newer version, but it would make it trivially easy to query for just the current versions.

    As long as you don’t have too many versions of each file I think your best solution is to do that part of the filtering client side.

    You probably want to make sure you have an index on metadata.ParentPath also if there are going to be many files stored.

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

Sidebar

Related Questions

I am writing a program using Delphi 2006 and storing data in XML files
i am storing files in database and this is the code i am using
For an iPhone Firemonkey application I am storing files (images) in the 'tmp' folder
I am using mongo for storing log files. Both mongoDB and mysql are running
I am using paperclip for storing files related to the model. The files can
I have this method to transfer files using a FTP Server: private void TransferNeededFiles(IEnumerable<string>
Greetings all, I'm trying to localize a .NET/C# project. I'm using string resource files
What is the best practices regarding storing files uploaded from users? Currently, I am
I am thinking of storing bunch of data in XML files. Each file will
For a project I'm working on for loading/storing data in files, I made the

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.