{"id":7235,"date":"2022-09-02T17:02:13","date_gmt":"2022-09-02T09:02:13","guid":{"rendered":"http:\/\/123.57.164.21\/?p=7235"},"modified":"2023-08-25T13:48:43","modified_gmt":"2023-08-25T05:48:43","slug":"ibm-cloud-mongodb-%e8%bf%9e%e6%8e%a5-tips","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=7235","title":{"rendered":"IBM Cloud MongoDB \u8fde\u63a5 Tips"},"content":{"rendered":"\n<p>\u5728IBM Cloud\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efa MongoDB\u670d\u52a1\uff0c\u6211\u4eec\u53ef\u4ee5\u70b9\u51fbOverView\u770b\u5230\u8fde\u63a5\u7684\u4e00\u4e9b\u4fe1\u606f\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-2-1024x506.png\" alt=\"\" class=\"wp-image-7236\" width=\"592\" height=\"292\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-2-1024x506.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-2-300x148.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-2-768x380.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-2-1536x759.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-2-830x410.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-2-230x114.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-2-350x173.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-2-480x237.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-2.png 1570w\" sizes=\"(max-width: 592px) 100vw, 592px\" \/><\/figure><\/div>\n\n\n\n<p>\u5728Endpoint\u4e2d\uff0c\u53ef\u4ee5\u770b\u5230\u8fde\u63a5\u7684\u4fe1\u606f\uff0c\u8fd8\u6709TSL\u8fde\u63a5\u9700\u8981\u7684CA\u8bc1\u4e66\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-3-1024x564.png\" alt=\"\" class=\"wp-image-7237\" width=\"588\" height=\"323\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-3-1024x564.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-3-300x165.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-3-768x423.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-3-1536x845.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-3-2048x1127.png 2048w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-3-830x457.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-3-230x127.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-3-350x193.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-3-480x264.png 480w\" sizes=\"(max-width: 588px) 100vw, 588px\" \/><\/figure><\/div>\n\n\n\n<p><strong>MongoDB Compass\u4e2d\u7684\u8fde\u63a5\u65b9\u6cd5<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u586b\u597dURI\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">mongodb:\/\/username:passwrd@xxxx:31236\/ibmclouddb?authSource=admin&amp;replicaSet=replset&amp;tls=true<\/pre>\n\n\n\n<p>\u9009\u62e9<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-4-1024x541.png\" alt=\"\" class=\"wp-image-7238\" width=\"738\" height=\"389\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-4-1024x541.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-4-300x158.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-4-768x405.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-4-1536x811.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-4-2048x1081.png 2048w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-4-830x438.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-4-230x121.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-4-350x185.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-4-480x253.png 480w\" sizes=\"(max-width: 738px) 100vw, 738px\" \/><\/figure><\/div>\n\n\n\n<p><strong>NodeJs TLS\u7684\u4f8b\u5b50<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">const MongoClient = require(\"mongodb\").MongoClient;\n\nlet connectionString = \"mongodb:\/\/&lt;username>:&lt;password>@&lt;host>:&lt;port>,&lt;host>:&lt;port>\/&lt;database>?authSource=admin&amp;replicaSet=replset\";\n\nlet options = {\n    tls: true,\n    tlsCAFile: `\/path\/to\/cert`,\n    useUnifiedTopology: true \n};\n\n\/\/ connects to a MongoDB database\nMongoClient.connect(connectionString, options, function (err, db) {\n    if (err) {\n        console.log(err);\n    } else {\n       \/\/ lists the databases that exist in the deployment\n        db.db('example').admin().listDatabases(function(err, dbs) {\n            console.log(dbs.databases);\n            db.close();\n        });\n    }\n});<\/pre>\n\n\n\n<p><strong>Java\u8fde\u63a5\u7684\u4f8b\u5b501<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>http:\/\/mongodb.github.io\/mongo-java-driver\/3.0\/driver\/reference\/connecting\/ssl\/<\/p>\n\n\n\n<p>\u901a\u8fc7\u4e0b\u9762\u7684\u547d\u4ee4\uff0c\u628aIBM cloud download\u4e0b\u6765\u7684 CA\u6587\u4ef6\u8f6c\u6362\u4e00\u4e0b\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    keytool -importcert -trustcacerts -file &lt;path to certificate authority file> \n        -keystore &lt;path to trust store> -storepass &lt;password><\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">keytool -importcert -trustcacerts -file \/Users\/Documents\/ca\/631b75c3-4296-4ce9-b0f2-426423c5b0e6 -keystore \/Users\/Documents\/ca\/sslkey -storepass test<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-5.png\" alt=\"\" class=\"wp-image-7243\" width=\"494\" height=\"120\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-5.png 818w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-5-300x73.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-5-768x186.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-5-230x56.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-5-350x85.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-5-480x116.png 480w\" sizes=\"(max-width: 494px) 100vw, 494px\" \/><\/figure><\/div>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import java.io.FileNotFoundException;\nimport java.net.UnknownHostException;\n\nimport org.springframework.beans.factory.annotation.Value;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.Configuration;\nimport org.springframework.context.annotation.Primary;\nimport org.springframework.data.mongodb.MongoDatabaseFactory;\nimport org.springframework.data.mongodb.core.MongoTemplate;\nimport org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory;\nimport org.springframework.util.ResourceUtils;\n\n\nimport com.mongodb.client.MongoClient;\nimport com.mongodb.client.MongoClients;\n\n@Configuration\npublic class MongoConfig {\n\n\t@Value(\"${ssl.key.path}\")\n\tprivate String sslkeypath;\n\n\tprivate String sslkeypass = \"test\";\n\n\tprivate String mongouri= \"mongodb:\/\/userid:passwod@ip:31236\/ibmclouddb?authSource=admin&amp;replicaSet=replset&amp;ssl=true\";\n\n\tprivate String dbname = \"testdb\";\n\n\t@Bean\n\tpublic MongoDatabaseFactory mongoDbFactory() throws FileNotFoundException {\n\n\t\tMongoClient mongoClient;\n\n                \/\/ ------\u6253\u6210jar\u4f1a\u62a5\u9519\uff0c\u4e0b\u9762\u8fd9\u79cd\u5199\u6cd5\u5f85\u9a8c\u8bc1\uff01----------\n\t\t\/\/ InputStream stream = getClass().getClassLoader().getResourceAsStream(cafile);\n\t\t\/\/ File caFile = new File(\"cafile\");\n                \/\/ FileUtils.copyInputStreamToFile(stream, caFile);\n                \/\/ -------------------------------------------\n          \n                \/\/ sslkey\u662f\u4e0a\u9762\u7528keytool,\u751f\u6210\u7684\u6587\u4ef6\n\t\tSystem.setProperty(\"javax.net.ssl.trustStore\",\n\t\t\t\tStringUtil.joinStr(ResourceUtils.getURL(\"classpath:\").getPath(), \"sslkey\"));\n                \/\/ sslkeypass\u662fkeytool\u751f\u6210\u6587\u4ef6\u65f6\u6307\u5b9a\u7684\u5bc6\u7801\n\t\tSystem.setProperty(\"javax.net.ssl.trustStorePassword\", sslkeypass);\n\n\t\tfinal String mongoURI = mongouri;\n\n\n\t\tmongoClient = MongoClients.create(mongoURI);\n\n\t\treturn new SimpleMongoClientDatabaseFactory(mongoClient, dbdbname);\n\t}\n\n\t@Bean\n\t@Primary\n\tpublic MongoTemplate mongoTemplate(MongoDatabaseFactory mongoDbFactory) throws UnknownHostException {\n\t\treturn new MongoTemplate(mongoDbFactory);\n\t}\n\n}<\/pre>\n\n\n\n<p>\u4f46\u662f\u4e0a\u9762\u7684\u65b9\u6cd5\u672c\u5730\u6d4b\u8bd5\u597d\u7528\uff0c\u5728IBM Cloud Engine\u4e0a\u4f1a\u51fa\u9519\u3002<\/p>\n\n\n\n<p><strong>Java\u8fde\u63a5\u7684\u4f8b\u5b50<\/strong>2<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.net.UnknownHostException;\nimport java.nio.charset.StandardCharsets;\nimport java.security.KeyManagementException;\nimport java.security.KeyStore;\nimport java.security.KeyStoreException;\nimport java.security.NoSuchAlgorithmException;\nimport java.security.cert.CertificateException;\nimport java.security.cert.CertificateFactory;\nimport java.security.cert.X509Certificate;\n\nimport javax.net.ssl.SSLContext;\nimport javax.net.ssl.TrustManagerFactory;\n\nimport org.springframework.beans.factory.annotation.Value;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.Configuration;\nimport org.springframework.context.annotation.Primary;\nimport org.springframework.data.mongodb.MongoDatabaseFactory;\nimport org.springframework.data.mongodb.core.MongoTemplate;\nimport org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory;\n\nimport com.mongodb.ConnectionString;\nimport com.mongodb.MongoClientSettings;\nimport com.mongodb.client.MongoClient;\nimport com.mongodb.client.MongoClients;\n\n@Configuration\npublic class MongoConfig {\n\n\n\tprivate String mongouri= \"mongodb:\/\/userid:passwod@ip:31236\/ibmclouddb?authSource=admin&amp;replicaSet=replset&amp;ssl=true\";\n\n\t@Value(\"${mongodb.db}\")\n\tprivate String dbname;\n\n\tprivate String certificateDecoded = \"-----BEGIN CERTIFICATE-----\\n\"\n\t\t\t+ \"xxxxxxIYKLSZthAzzXtJpTW1\\n\" + \"-----END CERTIFICATE-----\\n\" + \"\";\n\n\t@Bean\n\tpublic MongoDatabaseFactory mongoDbFactory() throws CertificateException, KeyStoreException,\n\t\t\tNoSuchAlgorithmException, IOException, KeyManagementException {\n\n\t\tfinal String mongoURI = mongouri;\n\n\t\tInputStream inputStream = new ByteArrayInputStream(certificateDecoded.getBytes(StandardCharsets.UTF_8));\n\t\tCertificateFactory certificateFactory = CertificateFactory.getInstance(\"X.509\");\n\t\tX509Certificate caCert = (X509Certificate) certificateFactory.generateCertificate(inputStream);\n\n\t\tTrustManagerFactory trustManagerFactory = TrustManagerFactory\n\t\t\t\t.getInstance(TrustManagerFactory.getDefaultAlgorithm());\n\t\tKeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());\n\t\tkeyStore.load(null); \n\t\tkeyStore.setCertificateEntry(\"caCert\", caCert);\n\n\t\ttrustManagerFactory.init(keyStore);\n\n\t\tSSLContext sslContext = SSLContext.getInstance(\"TLS\");\n\t\tsslContext.init(null, trustManagerFactory.getTrustManagers(), null);\n\n\t\tConnectionString cs = new ConnectionString(mongoURI);\n\t\tMongoClientSettings settings = MongoClientSettings.builder().applyConnectionString(cs)\n\t\t\t\t.applyToSslSettings(builder -> {\n\t\t\t\t\tbuilder.enabled(true);\n\t\t\t\t\tbuilder.context(sslContext);\n\t\t\t\t}).build();\n\n\t\tMongoClient client = MongoClients.create(settings);\n\n\t\treturn new SimpleMongoClientDatabaseFactory(client, dbname);\n\t}\n\n\t@Bean\n\t@Primary\n\tpublic MongoTemplate mongoTemplate(MongoDatabaseFactory mongoDbFactory) throws UnknownHostException {\n\t\treturn new MongoTemplate(mongoDbFactory);\n\t}\n\n}\n<\/pre>\n\n\n\n<p>\u4e5f\u53ef\u4ee5\u7528\u4e0b\u9762\u7684\u5199\u6cd5\uff0c\u628acertificateDecoded\u4f5c\u6210\u4e00\u4e2a\u6587\u4ef6\u3002\u7136\u540e\u8bfb\u53d6\u8fd9\u4e2a\u6587\u4ef6\uff0c\u6210\u5b57\u7b26\u4e32\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\nimport java.io.ByteArrayInputStream;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.nio.charset.StandardCharsets;\nimport java.security.KeyManagementException;\nimport java.security.KeyStore;\nimport java.security.KeyStoreException;\nimport java.security.NoSuchAlgorithmException;\nimport java.security.cert.CertificateException;\nimport java.security.cert.CertificateFactory;\nimport java.security.cert.X509Certificate;\nimport java.util.concurrent.TimeUnit;\n\nimport javax.net.ssl.SSLContext;\nimport javax.net.ssl.TrustManagerFactory;\n\nimport org.apache.commons.io.FileUtils;\nimport org.springframework.beans.factory.annotation.Value;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.Configuration;\nimport org.springframework.context.annotation.Primary;\nimport org.springframework.data.mongodb.MongoDatabaseFactory;\nimport org.springframework.data.mongodb.core.MongoTemplate;\nimport org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory;\n\nimport com.mongodb.ConnectionString;\nimport com.mongodb.MongoClientSettings;\nimport com.mongodb.client.MongoClient;\nimport com.mongodb.client.MongoClients;\n\n@Configuration\npublic class MongoConfig {\n\n\t@Value(\"${mongodb.uri}\")\n\tprivate String mongouri;\n\n\t@Value(\"${mongodb.db}\")\n\tprivate String dbName;\n\t\n\t@Value(\"${mongodb.cafile}\")\n\tprivate String cafile;\n\n\t@Bean\n\tpublic MongoDatabaseFactory mongoDbFactory() throws CertificateException, KeyStoreException,\n\t\t\tNoSuchAlgorithmException, IOException, KeyManagementException {\n        \n                \/\/ \u6ce8\u610f\u8fd9\u91cc\u9762\u8bfb\u53d6\u4e86\u672c\u5730\u7684\u4e00\u4e2a\u6587\u4ef6\uff0c\u6587\u4ef6\u91cc\u9762\u6709certificateDecoded\u4fe1\u606f\n\t\tInputStream stream = getClass().getClassLoader().getResourceAsStream(cafile);\n\t\tFile caFile = new File(\"cafile\");\n                FileUtils.copyInputStreamToFile(stream, caFile);\n\n                String certificateDecoded = \"\";\n\n\t\tFileInputStream fileInputStream = null;\n\t\ttry {\n\t\t\tfileInputStream = new FileInputStream(caFile);\n\t\t\tbyte[] bytes = new byte[2048];\n\t\t\tint readCount = fileInputStream.read(bytes);\n\t\t\tcertificateDecoded = new String(bytes, 0, readCount);\n\n\t\t} catch (FileNotFoundException e) {\n\t\t\te.printStackTrace();\n\t\t} finally {\n\t\t\tif (fileInputStream != null) {\n\t\t\t\tfileInputStream.close();\n\t\t\t}\n\t\t}\n\n\t\tInputStream inputStream = new ByteArrayInputStream(certificateDecoded.getBytes(StandardCharsets.UTF_8));\n\t\tCertificateFactory certificateFactory = CertificateFactory.getInstance(\"X.509\");\n\t\tX509Certificate caCert = (X509Certificate) certificateFactory.generateCertificate(inputStream);\n\n\t\tTrustManagerFactory trustManagerFactory = TrustManagerFactory\n\t\t\t\t.getInstance(TrustManagerFactory.getDefaultAlgorithm());\n\t\tKeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());\n\t\tkeyStore.load(null);\n\t\tkeyStore.setCertificateEntry(\"caCert\", caCert);\n\n\t\ttrustManagerFactory.init(keyStore);\n\n\t\tSSLContext sslContext = SSLContext.getInstance(\"TLS\");\n\t\tsslContext.init(null, trustManagerFactory.getTrustManagers(), null);\n\n\t\tConnectionString cs = new ConnectionString(mongouri);\n                \/\/ \u6ce8\u610f\u8fd9\u91cc\u9762\u7528\u5230\u4e86\u6570\u636e\u5e93\u8fde\u63a5\u6c60 \n\t\tMongoClientSettings settings = MongoClientSettings.builder().applyToConnectionPoolSettings(\n\t\t\t\t\t\tbuilder -> builder.maxWaitTime(10, TimeUnit.SECONDS).minSize(2).maxConnectionIdleTime(30, TimeUnit.SECONDS)).applyConnectionString(cs)\n\t\t\t\t.applyToSslSettings(builder -> {\n\t\t\t\t\tbuilder.enabled(true);\n\t\t\t\t\tbuilder.context(sslContext);\n\t\t\t\t}).build();\n\n\t\tMongoClient client = MongoClients.create(settings);\n\n\t\treturn new SimpleMongoClientDatabaseFactory(client, dbName);\n\t}\n\n\t@Bean\n\t@Primary\n\tpublic MongoTemplate mongoTemplate(MongoDatabaseFactory mongoDbFactory) {\n\t\treturn new MongoTemplate(mongoDbFactory);\n\t}\n\n}\n<\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-31-1024x801.png\" alt=\"\" class=\"wp-image-7316\" width=\"571\" height=\"447\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-31-1024x801.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-31-300x235.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-31-768x601.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-31-1536x1201.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-31-830x649.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-31-230x180.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-31-350x274.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-31-480x375.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-31.png 1578w\" sizes=\"(max-width: 571px) 100vw, 571px\" \/><figcaption>\u6570\u636e\u5e93\u8fde\u63a5\u6c60\u53c2\u6570\u8bf4\u660e<\/figcaption><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-30-1024x281.png\" alt=\"\" class=\"wp-image-7315\" width=\"604\" height=\"165\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-30-1024x281.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-30-300x82.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-30-768x211.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-30-1536x421.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-30-830x228.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-30-230x63.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-30-350x96.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-30-480x132.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/09\/\u56fe\u7247-30.png 1706w\" sizes=\"(max-width: 604px) 100vw, 604px\" \/><figcaption>\u6570\u636e\u5e93\u8fde\u63a5\u6c60\u53c2\u6570\u8bf4\u660e<\/figcaption><\/figure><\/div>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@RestController\n@RequestMapping(\"\/sample\/v1\")\npublic class SampleController {\n\n\t@Autowired\n\tprivate MongoTemplate mongoTemplate;\n\n\t@GetMapping(\"\/hello\")\n\tpublic String hello() {\n\t\tSet&lt;String> set = mongoTemplate.getCollectionNames();\n\t\tfor (String t : set) {\n\t\t\tSystem.out.println(t);\n\t\t}\n\t\treturn \"hello!!!\";\n\t}\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728IBM Cloud\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efa MongoDB\u670d\u52a1\uff0c\u6211\u4eec\u53ef\u4ee5\u70b9\u51fbOverView\u770b\u5230\u8fde\u63a5\u7684\u4e00\u4e9b\u4fe1\u606f\u3002 \u5728 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,23],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/7235"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7235"}],"version-history":[{"count":9,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/7235\/revisions"}],"predecessor-version":[{"id":12169,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/7235\/revisions\/12169"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}