[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 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, |
| 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, |
| 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:
And
|