[CXX-620] How to set _id in gridfs and append to a file in gridfs? Created: 06/Jul/15  Updated: 11/Sep/19  Resolved: 27/Jul/15

Status: Closed
Project: C++ Driver
Component/s: API
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Yuncong Zhang Assignee: Unassigned
Resolution: Done Votes: 0
Labels: legacy-cxx
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

I can use gridfs to do the initial loading with storeFile function. How can I set the _id field for future appending data to the file?

I think I should use GridFileBuilder class, but I didn't find any example in the cxx driver. Can someone help provide an example?

Basically, I want insert data to
dbname.collection_files:
{_id:"unique_string", filename:"my_file_name"...}

After a while, the "my_file_name" would have something append to the end, and I want to append the data based on "unique_string" to the gridfs for the same data.

How can I do it?

Thanks in advance!



 Comments   
Comment by Samantha Ritter (Inactive) [ 27/Jul/15 ]

Hi Yuncong,

Yes, it's definitely not an ideal solution. File appending in GridFS is an often asked-for feature, but unfortunately the current GridFS spec does not allow for a safe implementation. In the future we hope to move towards a GridFS model that can handle the sort of concurrency issues file updates introduce.

I'll close this ticket then, but feel free to re-open it if you'd like help finding an alternative workflow or run into any other issues.

Thanks,
Sam

Comment by Yuncong Zhang [ 27/Jul/15 ]

Hi Sam,

That would be too costly to perform. We will think other alternatives.

Thank you.

Yuncong

Comment by Samantha Ritter (Inactive) [ 27/Jul/15 ]

Hi yuncong.zhang,

Unfortunately there is no way to append to a file once it has been stored in GridFS. Some other drivers may have offered this feature, but this behavior is deprecated and the CXX driver does not allow for appending to a file.

If your application really needs to append to files, the workaround is to read the file out of GridFS, append to it in your application, and insert it into GridFS as a new file. This is a slow workflow, but it will get the job done. Please let me know if this might work for you. If not, we can try to come up with some other workarounds that might fit your application better.

Thanks,
Sam

Comment by Yuncong Zhang [ 07/Jul/15 ]

Or put it this way:

Is it a bad design to append file in the gridfs?

I see node driver has removed the Grid Object, link below:
https://mongodb.github.io/node-mongodb-native/2.0/tutorials/changes-from-1.0/

The grid object has been removed as it’s not widely used and offers very limited GridStore capabilities.

And

Thus w+ in 2.0 only allows for changes to the file metadata and does not allow for appending to a file avoiding the possible data corruption.

Generated at Wed Feb 07 21:59:46 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.