@@ -42,6 +42,7 @@ package eu.vironlab.cloudnetmongodb;
4242
4343import com.mongodb.BasicDBObject
4444import com.mongodb.client.MongoCollection
45+ import com.mongodb.client.model.InsertOneOptions
4546import de.dytanic.cloudnet.common.concurrent.ITask
4647import de.dytanic.cloudnet.common.concurrent.ITaskListener
4748import 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