-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
-
Go Drivers
-
None
-
None
-
None
-
None
-
None
-
None
Detailed steps to reproduce the problem?
When using bucket.Find() to get a mongo.GridFSFile, the resulting cursor entries to not decode _id into mongo.GridFSFile.ID. Here is a test to reproduce:
func TestDecodingIntoID(t *testing.T) { client, err := mongo.Connect() require.NoError(t, err) defer client.Disconnect(context.Background()) // Get the database and create a GridFS bucket db := client.Database("gridfs_test_db") // Drop the collection db.Collection("myfiles.files").Drop(context.Background()) db.Collection("myfiles.chunks").Drop(context.Background()) bucket := db.GridFSBucket(options.GridFSBucket().SetName("myfiles")) // Data to upload fileName := "example-file.txt" fileContent := []byte("Hello GridFS! This is a test file.") // Upload data into GridFS uploadStream, err := bucket.OpenUploadStream(context.Background(), fileName) require.NoError(t, err) _, err = uploadStream.Write(fileContent) require.NoError(t, err) uploadStream.Close() // Verify the file metadata fileCursor, err := bucket.Find(context.Background(), bson.D{}) require.NoError(t, err) for fileCursor.Next(context.Background()) { var file mongo.GridFSFile err := fileCursor.Decode(&file) fmt.Println(file) require.NoError(t, err) assert.NotNil(t, file.ID) } }
Output:
=== RUN TestDecodingIntoID {<nil> 34 261120 2025-05-11 03:45:14.782 +0000 UTC } gridfs_test.go:53: Error Trace: /Users/preston.vasquez/Developer/dev/mongo-go-driver/v2/inline/gridfs/gridfs_test.go:53 Error: Expected value not to be nil. Test: TestDecodingIntoID --- FAIL: TestDecodingIntoID (0.05s) FAIL exit status 1 FAIL github.com/prestonvasquez/mongo-go-driver/v2/inline/gridfs 0.609s
Definition of done: what must be done to consider the task complete?
The unmarshaler for gridfs.File was not carried over in v2: https://github.com/mongodb/mongo-go-driver/blob/ba0613abf852d2ad1ed3d8c748500ddf67a13347/mongo/gridfs/download_stream.go#L89. Extend mongo.GridFSFile with this method.
When deprecating this data in GODRIVER-2606 it looks like we did not follow up with the suggestion:
Replace with an UnmarshalBSON function on the existing unmarshalFile type and convert unmarshalFile into File in openDownloadStream.
The exact Go version used, with patch level:
go version go1.23.1 darwin/arm64
The exact version of the Go driver used:
2.2.1
- related to
-
GODRIVER-2606 Deprecate unused functionality in preparation to remove it in Go Driver 2.0
-
- Closed
-
-
GODRIVER-2617 Remove or un-export all currently deprecated code in Go Driver 2.0
-
- Closed
-