Thao tác com/mongodb ReadOperation

Một thẻ đã tồn tại với tên chi nhánh được cung cấp. Nhiều lệnh Git chấp nhận cả tên thẻ và tên nhánh, vì vậy việc tạo nhánh này có thể gây ra hành vi không mong muốn. Bạn có chắc chắn muốn tạo nhánh này không?

com. mongodb. hoạt độngĐọchoạt động

Javadoc

Thao tác đọc từ máy chủ MongoDB

Phương pháp được sử dụng nhiều nhất

  • hành hình

    Thực thi chung có thể trả về bất kỳ thứ gì thuộc loại T

Phổ biến trong Java

  • Các cuộc gọi nghỉ ngơi phản ứng bằng cách sử dụng mẫu nghỉ ngơi mùa xuân
  • getOriginalFilename (Tệp nhiều phần)

    Trả lại tên tệp gốc trong hệ thống tệp của khách hàng. Điều này có thể chứa thông tin đường dẫn tùy thuộc vào

  • putExtra (Ý định)
  • getSharedPreferences (Ngữ cảnh)
  • EOFException (java. io)

    Bị ném khi chương trình gặp phần cuối của tệp hoặc luồng trong khi thao tác nhập liệu

  • Bộ đệm byte (java. không)

    Bộ đệm cho byte. Bộ đệm byte có thể được tạo theo một trong các cách sau. * #chỉ định

  • Bộ sắp xếp (java. sử dụng)

    SortedSet là Set lặp qua các phần tử của nó theo thứ tự đã sắp xếp. Thứ tự được xác định

  • Bản đồ cây (java. sử dụng)

    Đi qua các nút của cây từ trái sang phải hoặc từ phải sang trái. Lưu ý rằng trong các lần lặp giảm dần, tiếp theo

  • JTextField (javax. xích đu)
  • StringUtils (org. apache. của chung. lang)

    Các thao tác trên java. lang thang. Chuỗi không an toàn. * IsEmpty/IsBlank - kiểm tra xem Chuỗi có chứa

  • Các plugin hàng đầu cho Android Studio

Tôi đang làm việc trên một chương trình nâng cấp

Đối mặt với vấn đề với chuỗi kết nối

public static void main(String[] args) throws Throwable {
        MongoCredential credential = MongoCredential.createCredential("user", "dbName", "password".toCharArray());
        Block localhost = builder -> builder.hosts(singletonList(new ServerAddress("host.mongodb.net", 27017)));
        MongoClientSettings settings = MongoClientSettings.builder()
                .applyToClusterSettings(localhost)
                .credential(credential)
                .build();
        MongoClient client = MongoClients.create(settings);
        MongoCollection col = client.getDatabase("test").getCollection("col");
        System.out.println(col.countDocuments());

}

lỗi

Exception in thread "main" java.lang.NoClassDefFoundError: com/mongodb/internal/connection/DefaultClusterFactory
	at com.mongodb.client.internal.MongoClientImpl.createCluster(MongoClientImpl.java:208)
	at com.mongodb.client.internal.MongoClientImpl.(MongoClientImpl.java:63)
	at com.mongodb.client.MongoClients.create(MongoClients.java:108)
	at com.mongodb.client.MongoClients.create(MongoClients.java:50)
	at ServiceApplication.main(ServiceApplication.java:48)
Caused by: java.lang.ClassNotFoundException: com.mongodb.internal.connection.DefaultClusterFactory
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	.. 5 more

Quá trình kết thúc với mã thoát 1

đoạn mã khác mà tôi đã thử là.
@Bean
public MongoDatabaseFactory mongoDatabaseFactory() ném NoSuchAlgorithmException, KeyManagementException {

    SSLContext sslContext;
    try {
        sslContext = SSLContext.getInstance(InmarsatConstants.SSL_PROTOCOL);

        // set up a TrustManager that trusts everything
        sslContext.init(null, new TrustManager[]{new X509TrustManager() {

            @Override
            public void checkClientTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) throws CertificateException {
            }

            @Override
            public void checkServerTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) throws CertificateException {
            }

            @Override
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return new java.security.cert.X509Certificate[0];
            }
        }}, new SecureRandom());
    } catch (NoSuchAlgorithmException e) {
        throw new NoSuchAlgorithmException(e);
    } catch (KeyManagementException e) {
        throw new KeyManagementException(e);
    }
    MongoCredential credential = MongoCredential.createCredential(mongoDbUserName,mongoDbName,mongoDbPassword.toCharArray());
    MongoClient mongoClient = MongoClients.create(
            MongoClientSettings.builder()
                    .applyToClusterSettings(builder ->
                            builder.hosts(Arrays.asList(new ServerAddress("mongodb://"+mongoDbCLientHostName, 27017))))
                    .credential(credential)
                    .build());

    return new SimpleMongoClientDatabaseFactory(mongoClient,mongoDbName);
}

@Bean
public MongoTemplate mongoTemplate() throws KeyManagementException, NoSuchAlgorithmException {
    return new MongoTemplate(mongoDatabaseFactory());
}
public @Bean
com.mongodb.client.MongoClient mongoClient() throws NoSuchAlgorithmException, KeyManagementException {
    SSLContext sslContext;
    try {
        sslContext = SSLContext.getInstance(InmarsatConstants.SSL_PROTOCOL);

        // set up a TrustManager that trusts everything
        sslContext.init(null, new TrustManager[]{new X509TrustManager() {

            @Override
            public void checkClientTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) throws CertificateException {
            }

            @Override
            public void checkServerTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) throws CertificateException {


            }

            @Override
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return new java.security.cert.X509Certificate[0];
            }
        }}, new SecureRandom());
    } catch (NoSuchAlgorithmException e) {
        throw new NoSuchAlgorithmException(e);
    } catch (KeyManagementException e) {
        throw new KeyManagementException(e);
    }


    CodecRegistry pojoCodecRegistry = fromProviders(PojoCodecProvider.builder().automatic(true).build());
    CodecRegistry codecRegistry = fromRegistries(MongoClientSettings.getDefaultCodecRegistry(), pojoCodecRegistry);


    MongoCredential credential = MongoCredential.createCredential(mongoDbUserName,mongoDbName,mongoDbPassword.toCharArray());
    MongoClient mongoClient = MongoClients.create(
            MongoClientSettings.builder()
                    .applyToClusterSettings(builder ->
                            builder.hosts(Arrays.asList(new ServerAddress("mongodb://"+mongoDbCLientHostName, 27017))))
                    .credential(credential).codecRegistry(codecRegistry)
                    .build());
    return mongoClient;

}

lỗi

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.MongoDatabaseFactory]: Factory method 'mongoDatabaseFactory' threw exception; nested exception is com.mongodb.MongoException: host and port should be specified in host:port format
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:651)
	.. 24 common frames omitted
Caused by: com.mongodb.MongoException: host and port should be specified in host:port format
	at com.mongodb.ServerAddress.(ServerAddress.java:125)
	at ServiceApplication.lambda$mongoDatabaseFactory$0(ServiceApplication.java:96)
	at com.mongodb.MongoClientSettings$Builder.applyToClusterSettings(MongoClientSettings.java:230)
	at ServiceApplication.mongoDatabaseFactory(ServiceApplication.java:95)
	at ServiceApplication$$EnhancerBySpringCGLIB$$c3b4fc1b.CGLIB$mongoDatabaseFactory$0()
	at ServiceApplication$$EnhancerBySpringCGLIB$$c3b4fc1b$$FastClassBySpringCGLIB$$22498f2e.invoke()
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)

Phụ thuộc được sử dụng cho cả hai trường hợp


            org.springframework.data
            spring-data-mongodb
            3.2.3
        

            org.mongodb
            mongodb-driver-sync
            4.2.3