From ffa5bcaf4e4a3129177c304ad326294f84de70fb Mon Sep 17 00:00:00 2001 From: ZhuJHua <1624109111@qq.com> Date: Sun, 1 Dec 2024 02:30:47 +0800 Subject: [PATCH] chore(git): add attributes --- .gitattributes | 1 + .../main/kotlin/cn/yooss/util/DatabaseUtil.kt | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 server/src/main/kotlin/cn/yooss/util/DatabaseUtil.kt diff --git a/.gitattributes b/.gitattributes index 7d63010..a2b8357 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ *.tflite filter=lfs diff=lfs merge=lfs -text +* text=auto eol=lf diff --git a/server/src/main/kotlin/cn/yooss/util/DatabaseUtil.kt b/server/src/main/kotlin/cn/yooss/util/DatabaseUtil.kt new file mode 100644 index 0000000..2e9e65d --- /dev/null +++ b/server/src/main/kotlin/cn/yooss/util/DatabaseUtil.kt @@ -0,0 +1,44 @@ +package cn.yooss.util + +/* + * Author: ZhuJHua + * Date: 2024/11/25 22:08 + * Description: Database + */ + +import com.mongodb.ConnectionString +import com.mongodb.MongoClientSettings +import com.mongodb.ServerApi +import com.mongodb.ServerApiVersion +import com.mongodb.kotlin.client.coroutine.MongoClient +import kotlinx.coroutines.runBlocking +import org.bson.Document + + +object MongoClientConnectionExample { + + fun main() { + // Replace the placeholders with your credentials and hostname + val connectionString = + "" + + val serverApi = ServerApi.builder() + .version(ServerApiVersion.V1) + .build() + + val mongoClientSettings = MongoClientSettings.builder() + .applyConnectionString(ConnectionString(connectionString)) + .serverApi(serverApi) + .build() + + // Create a new client and connect to the server + MongoClient.create(mongoClientSettings).use { mongoClient -> + val database = mongoClient.getDatabase("admin") + runBlocking { + database.runCommand(Document("ping", 1)) + } + println("Pinged your deployment. You successfully connected to MongoDB!") + } + } + +}