[JAVA-2884] ConnectionString streamType not applied to MongoClientSettings Created: 06/Jun/18  Updated: 06/Dec/18  Resolved: 06/Dec/18

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

Type: Bug Priority: Major - P3
Reporter: Graeme Rocher Assignee: Jeffrey Yemin
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Related
is related to JAVA-3114 Deprecate ConnectionString streamType... Closed

 Description   

It seems there is no way to specify the streamType and also provide custom settings to mongo (like the codecs etc.) this is because the method in the com.mongodb.async.client.MongoClients is private:

 

private static MongoClient create(final MongoClientSettings settings,
                                      @Nullable final MongoDriverInformation mongoDriverInformation,
                                      @Nullable final String requestedStreamType)

So if you pass a ConnectionString you cannot specify codecs. If you pass a MongoClientSettings you can specify codecs but not the requestedStreamType

 



 Comments   
Comment by Jeffrey Yemin [ 06/Dec/18 ]

Hi graemerocher

Sorry for the slow response on this. We were considering our options, and have decided not to fix this and instead deprecate the streamType query parameter. Please see JAVA-3114 for the rationale, and comment there with any further feedback.

Hope this doesn't cause too much pain; I think it's the right way to go long term for the driver.

Comment by Ian Whalen (Inactive) [ 19/Nov/18 ]

Putting into investigating for Jeff to figure out whether we can/should do a short term fix here to make streamType work with mongo client settings or just remove streamType.

Comment by Jeffrey Yemin [ 06/Jun/18 ]

OK, I see.  I think you'll have to specify the stream type programmatically for now (via MongoClientSettings.Builder#streamFactoryFactory), and we'll address this in an upcoming release.

 

 

Comment by Graeme Rocher [ 06/Jun/18 ]

That is what we are doing, but if you look at the code MongoClients calls connectionString.getStreamType()

     return create(MongoClientSettings.builder().applyConnectionString(connectionString).build(),
                mongoDriverInformation, connectionString.getStreamType());

And delegates to a private method that is not accessible and there is no public method that takes a settings and a stream type
 

Comment by Jeffrey Yemin [ 06/Jun/18 ]

The way to do it is to apply the connection string to the MongoClientSettings:

import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings;
import com.mongodb.async.client.MongoClient;
import com.mongodb.async.client.MongoClients;
import com.mongodb.connection.netty.NettyStreamFactoryFactory;
import org.bson.codecs.configuration.CodecRegistries;
 
public class JAVA2884 {
    public static void main(String[] args) {
        ConnectionString connectionString = new ConnectionString("mongodb://localhost");
        MongoClientSettings settings =
                MongoClientSettings.builder()
                .applyConnectionString(connectionString)
                .codecRegistry(CodecRegistries.fromRegistries(..., MongoClientSettings.getDefaultCodecRegistry()))
                .streamFactoryFactory(NettyStreamFactoryFactory.builder().build())
                .build();
 
        MongoClient mongoClient = MongoClients.create(settings);
    }
}

This particular code sample requires the com.mongodb.MongoClientSettings class introduced in the 3.7.1 driver. The code for 3.6 is similar but would use the now deprecated com.mongodb.async.client.MongoClientSettings.

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