[JAVA-3737] Add custom row on GridFs fs.files collection Created: 20/May/20  Updated: 13/Mar/21  Resolved: 02/Jun/20

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

Type: Improvement Priority: Major - P3
Reporter: Matteo Pileggi [X] Assignee: Ross Lawley
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related

 Description   

Hi,

I can't find a way with new reactive stream api to add a custom row on fs.files collection of gridfs.

On my old (that run in production) I was able to add custom row on 
com.mongodb.gridfs.GridFSInputFile using

gridFSInputFile.put("CUSTOM_ROW", myCustomRow);

The com.mongodb.reactivestreams.client.gridfs.GridFSBucket only allows to add metadata via GridFSUploadOptions.

 

But I've 16TB on my mongodb and I can't change the structure of my document.

By the way, this customRow,  is also my sharding key...

 

Can you add this features (or suggest me a workaround)?

 

regards

matpil

 



 Comments   
Comment by Matteo Pileggi [X] [ 13/Mar/21 ]

Finally I solved my problem starting by this link:
https://mongodb.github.io/mongo-java-driver/3.12/bson/codecs/

then I rewrited the GridFS* classes.

Comment by Matteo Pileggi [X] [ 05/Mar/21 ]

Hi,

I've tried to create a custom Provider (with a custom codec).
But how can I register in a "private static final" field on MongoClientSettins?

public final class MyMongoClientSettings {
    private static final CodecRegistry DEFAULT_CODEC_REGISTRY =
            fromProviders(asList(new ValueCodecProvider(),
                    new BsonValueCodecProvider(),
                    new DBRefCodecProvider(),
                    new DBObjectCodecProvider(),
                    new DocumentCodecProvider(new DocumentToDBRefTransformer()),
                    new IterableCodecProvider(new DocumentToDBRefTransformer()),
                    new MapCodecProvider(new DocumentToDBRefTransformer()),
                    new GeoJsonCodecProvider(),
                    new GridFSFileCodecProvider(),
             -->    new MyCustomGridFSFileCodecProvider(),
                    new Jsr310CodecProvider(),
                    new BsonCodecProvider()));

Can you suggest me a way?
As you see, I've try to re-implement MongoClientSettings but also I've to create a custom MongoClient... Is this the right way?!?!?
Somewhere there is a "ProviderRegistry.addProvider" that I can use?

Regards

matpil

ps. I know that this issue is closed, but can you answer me anyway?

Comment by Ross Lawley [ 02/Jun/20 ]

Hi matteo.pileggi@cerved.com,

Thanks for the ticket, the reactive streams GridFS API adheres to the GridFS Specification title which mandates that metadata is stored in a sub-document, rather than at the top level.

The legacy GridFS API doesn't adhere to the spec and that is why you are seeing a difference.

However, all isn't necessarily lost as the GridFSFileCodec handles the conversion of the GridFSFile to a BsonDocument. In theory you could register you're own codec to handle GridFSFiles and extract the CUSTOM_ROW metadata and encode that at the top level rather than in the metadata sub document.

This would allow you to continue using the same shard key and update to the reactive streams API.

I hope that helps,

Ross

Generated at Thu Feb 08 09:00:18 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.