將mongoDB改成需登入

This commit is contained in:
Raymond Yang 2023-05-18 09:29:20 +08:00
parent a2acb7b928
commit 7c68dc5ceb
3 changed files with 18 additions and 18 deletions

View File

@ -7,7 +7,7 @@ import org.litote.kmongo.*
import org.litote.kmongo.id.toId
class MaterialService {
private val client = KMongo.createClient("mongodb://www.ray650128.com:27017")
private val client = KMongo.createClient("mongodb://ray650128:Zx650128!@www.ray650128.com:27017")
private val database = client.getDatabase("ar_system")
private val materialCollection = database.getCollection<Material>()
@ -31,6 +31,7 @@ class MaterialService {
val updateResult = materialCollection.replaceOne(
material.copy(
name = request.name,
fileTag = request.fileTag,
updatedAt = request.updatedAt
)
)

View File

@ -7,7 +7,7 @@ import org.litote.kmongo.*
import org.litote.kmongo.id.toId
class ModelService {
private val client = KMongo.createClient("mongodb://www.ray650128.com:27017")
private val client = KMongo.createClient("mongodb://ray650128:Zx650128!@www.ray650128.com:27017")
private val database = client.getDatabase("ar_system")
private val arModelCollection = database.getCollection<ArModel>()
@ -26,22 +26,21 @@ class ModelService {
return arModelCollection.find(ArModel::ownerId eq bsonId).toList()
}
fun updateById(id: String, request: ArModel): Boolean =
findById(id)?.let { arModel ->
val updateResult = arModelCollection.replaceOne(
arModel.copy(
name = request.name,
position = request.position,
rotation = request.rotation,
scale = request.scale,
modelData = request.modelData,
events = request.events,
childEvents = request.childEvents,
updatedAt = request.updatedAt
)
fun updateById(id: String, request: ArModel): Boolean = findById(id)?.let { arModel ->
val updateResult = arModelCollection.replaceOne(
arModel.copy(
name = request.name,
position = request.position,
rotation = request.rotation,
scale = request.scale,
modelData = request.modelData,
events = request.events,
childEvents = request.childEvents,
updatedAt = request.updatedAt
)
updateResult.modifiedCount == 1L
} ?: false
)
updateResult.modifiedCount == 1L
} ?: false
fun deleteById(id: String): Boolean {
val deleteResult = arModelCollection.deleteOneById(ObjectId(id))

View File

@ -6,7 +6,7 @@ import org.litote.kmongo.*
import org.litote.kmongo.id.toId
class UserService {
private val client = KMongo.createClient("mongodb://www.ray650128.com:27017")
private val client = KMongo.createClient("mongodb://ray650128:Zx650128!@www.ray650128.com:27017")
private val database = client.getDatabase("ar_system")
private val userCollection = database.getCollection<User>()