Skip to content
This repository was archived by the owner on Apr 20, 2022. It is now read-only.

Commit 9b5f92e

Browse files
author
InfinityDevFlo
committed
Fixed inser of Key
1 parent 928aa8c commit 9b5f92e

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/main/kotlin/eu/vironlab/cloudnetmongodb/MongoDatabase.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ package eu.vironlab.cloudnetmongodb;
4242

4343
import com.mongodb.BasicDBObject
4444
import com.mongodb.client.MongoCollection
45+
import com.mongodb.client.model.InsertOneOptions
4546
import de.dytanic.cloudnet.common.concurrent.ITask
4647
import de.dytanic.cloudnet.common.concurrent.ITaskListener
4748
import de.dytanic.cloudnet.common.concurrent.ListenableTask
@@ -60,7 +61,7 @@ class MongoDatabase(mongoDatabaseProvider: MongoDatabaseProvider, private val na
6061

6162
companion object {
6263
@JvmStatic
63-
var COLLECTION_KEY = "__key__"
64+
var COLLECTION_KEY = "_id"
6465
}
6566

6667
val collection: MongoCollection<Document>
@@ -79,11 +80,12 @@ class MongoDatabase(mongoDatabaseProvider: MongoDatabaseProvider, private val na
7980
override fun insert(key: String, document: JsonDocument): Boolean = if (contains(key)) {
8081
update(key, document)
8182
} else {
82-
collection.insertOne(Document.parse(document.toJson())).wasAcknowledged()
83+
collection.insertOne(Document.parse(document.toJson()).append(COLLECTION_KEY, key)).wasAcknowledged()
8384
}
8485

8586
override fun update(key: String, document: JsonDocument): Boolean = if (contains(key)) {
86-
collection.replaceOne(BasicDBObject(COLLECTION_KEY, key), Document.parse(document.toJson())).wasAcknowledged()
87+
collection.replaceOne(BasicDBObject(COLLECTION_KEY, key), Document.parse(document.toJson()).append(
88+
COLLECTION_KEY, key)).wasAcknowledged()
8789
} else {
8890
insert(key, document)
8991
}

0 commit comments

Comments
 (0)