Skip to content
This repository has been archived by the owner on Oct 3, 2020. It is now read-only.

Commit

Permalink
delete working
Browse files Browse the repository at this point in the history
  • Loading branch information
fulton committed Apr 29, 2020
1 parent 57f12cb commit 2f6d564
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/main/java/com/andromeda/araserver/util/DatabaseClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.mongodb.client.MongoDatabase
import com.mongodb.connection.ClusterSettings
import com.mongodb.connection.SslSettings
import org.bson.Document
import com.mongodb.client.model.Filters;
import java.util.*


Expand Down Expand Up @@ -68,7 +69,6 @@ class DatabaseClient {
fun <T> getAll(userId: String, clazz: Class<T>): ArrayList<T> {
val toReturn = arrayListOf<T>()
val find = database.getCollection(userId).find()
val iterator = find.iterator()
find.forEach {
try {
val any = it.get("document") as org.bson.Document
Expand All @@ -89,5 +89,10 @@ class DatabaseClient {
document["document"] = Document.parse(toJson)
return document
}
fun delete(userId: String, id: String){
val document = Document()
document["_id"] = id
database.getCollection(userId).deleteOne(Filters.eq("_id", id))
}

}
4 changes: 3 additions & 1 deletion src/test/java/com/andromeda/araserver/test/DBtest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ class DBtest {
@Test
fun test(){
val databaseClient = DatabaseClient()
databaseClient.new("test-${System.currentTimeMillis()}", "test", OutputModel("", "", "", "", "", ""))
val id = "test-${System.currentTimeMillis()}"
databaseClient.new(id, "test", OutputModel("", "", "", "", "", ""))
println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
val message = databaseClient.getAll<OutputModel>("test", OutputModel::class.java)
println(message)
message.forEach {
println(it)
}
println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
databaseClient.delete("test", id)

}
}

0 comments on commit 2f6d564

Please sign in to comment.