[GODRIVER-2058] Allow setting uploadDate on gridfs upload file Created: 23/Jun/21  Updated: 10/Aug/21  Resolved: 10/Aug/21

Status: Closed
Project: Go Driver
Component/s: GridFS
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor - P4
Reporter: Ed Pelc Assignee: Benji Rewis (Inactive)
Resolution: Done Votes: 0
Labels: feature, mgocompat, post-5.0
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Issue split
Related

 Description   

You should be able to set the `uploadDate` field when opening a gridfs upload stream. Right now it always uses `time.Now()`. I believe you'd want to add this as a method like `options.GridFSUpload().SetUploadDate()`.

 

The old mgo driver use to allow this iirc and either way it is useful for controlling more aspects of gridfs files instead of having to stick it in metadata.



 Comments   
Comment by Benji Rewis (Inactive) [ 10/Aug/21 ]

Elaborated in the documentation for UploadDate. Thanks again for your report epelc@greatcloak.com! The associated DOCSP ticket is listed as "Open".

Comment by Githook User [ 10/Aug/21 ]

Author:

{'name': 'Benjamin Rewis', 'email': '32186188+benjirewis@users.noreply.github.com', 'username': 'benjirewis'}

Message: GODRIVER-2058 Document that File UploadDate is not configurable (#711)
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/ccd27717f6ed6ba4f77b3213df84c1f7bc3eb630

Comment by Benji Rewis (Inactive) [ 30/Jul/21 ]

Hello again epelc@greatcloak.com!

That sounds like a plan. Here's an addition to our current documentation in the Go driver: https://github.com/mongodb/mongo-go-driver/pull/711.

I've filed an internal documentation ticket to request that https://docs.mongodb.com/manual/core/gridfs/ be updated, but because the documentation project is internal you might not be able to see it in the Issue Links off of this ticket. I'll talk to the docs team about updating the security level and make sure to keep you abreast of any possible changes to the official documentation.

Comment by Ed Pelc [ 29/Jul/21 ]

Hi Benji,

Thanks for working on this. I think it's ok to keep it readonly but I'd strongly request it be documented in the go driver and also on the official gridfs docs. Basically something saying the drivers manage this field and it is explicitly meant to be read only/set by the driver at file upload time(also recommend using the metadata field to store your own date).

https://docs.mongodb.com/manual/core/gridfs/

I think if the drivers are going to take that stance it should be written down prominently to help avoid people potentially going down a rabbit hole.

Comment by Benji Rewis (Inactive) [ 28/Jul/21 ]

Hello again epelc@greatcloak.com.

The associated drivers ticket (DRIVERS-1845), which was a feature request to consider making the uploadDate field configurable as a cross-drivers change, has been closed. In short, they've suggested that users in your position make use of the metadata field, described here in cross-drivers specifications and available here in the Go driver. The uploadDate would still contain the time the file was uploaded to GridFS, but the metadata field could hold the actual upload date from the third-party storage system.

Let us know if that still introduces a lot of friction to your migration from mgo, and we can certainly brainstorm other workarounds.

Comment by Benji Rewis (Inactive) [ 13/Jul/21 ]

Hello epelc@greatcloak.com !

Thanks again for your feature request. Your case sounds totally reasonable, and we’d like to make your migration from mgo as seamless as possible.

The GridFS API is defined by a cross-drivers specification, and it currently requires that uploadDate be the current time when a file is uploaded. So, I’ve created DRIVERS-1845 to consider making that field configurable as a cross-drivers change.

Comment by Ed Pelc [ 07/Jul/21 ]

Hi Matt,

 

  • Not using indexes, it's just a field we show to end users.
  • I'd like to support this since our download system allows storing generated files but also files we pull from other systems where a created at/upload date is set by an external system instead of us. Ideally we'd track both but in this case we just need the actual upload date from the third party so it's simpler to just use the builtin upload date field.
  • We use to use the mgo driver and it supported this
Comment by Matt Dale [ 07/Jul/21 ]

Hey epelc@greatcloak.com thanks for this feature request! I have a few questions to help us better understand your use case for setting an alternate uploadDate value.

  • Are you using the indexes created for uploadDate to find or order GridFS files?
  • Are there any additional behaviors that setting uploadDate supports but adding a date to the GridFS file metadata doesn't support?
  • Are you currently or did you recently migrate from mgo to the mongo-go-driver?

Unfortunately, we won't be able to pick up any feature requests until the MongoDB Server v5.0 release on July 13th. Thanks for your patience!

Comment by Ed Pelc [ 23/Jun/21 ]

This would be where it'd be used internally.

`createFilesCollDoc`

https://github.com/mongodb/anser/blob/main/vendor/go.mongodb.org/mongo-driver/mongo/gridfs/upload_stream.go#L212

Generated at Thu Feb 08 08:37:44 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.