mirror of
https://github.com/ZhuJHua/moodiary.git
synced 2026-04-04 23:29:01 +08:00
chore(git): add attributes
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -1 +1,2 @@
|
||||
*.tflite filter=lfs diff=lfs merge=lfs -text
|
||||
* text=auto eol=lf
|
||||
|
||||
44
server/src/main/kotlin/cn/yooss/util/DatabaseUtil.kt
Normal file
44
server/src/main/kotlin/cn/yooss/util/DatabaseUtil.kt
Normal file
@@ -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!")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user