#My plugin will NOT START (and I suspect it's MongoDB) and I don't know why
1 messages ยท Page 1 of 1 (latest)
<@&987246584574140416> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
Reading this, my connection returns null from vault, and I severely suspect that to come from databaseConnection variable (MongoDBDatabaseConnection.kt, because of unfixed past experiences),
I don't know why it's just returning null though, didn't handle that with a try/catch most likely.
you're probably wondering some questions:
-
well, did you confirm the indention of the YAML files? and does the variables of
mongodb-database-collectionand others exist? perhaps you're using another file on accident.
I have confirmed and this is not the case. -
you probably put in the wrong collection/database, check again perhaps?
I have tried checking multiple times, even recreating my cluster, and it doesn't work thus returning null.
I uploaded your attachments as gist. That way, they are easier to read for everyone, especially mobile users ๐
thank you tj-bot
VaultEconomySupport.kt line 21 refers to MongoDBDatabaseConnect (val databaseConnect: MongoDBDatabaseConnect = greenBank.mongoConnect!!) so my databaseConnect is the imposter here
~
and we all know the impostor is sus
Closed the thread due to inactivity.
If your question was not resolved yet, feel free to just post a message to reopen it, or create a new thread. But try to improve the quality of your question to make it easier to help you ๐
unresolved.
is there something i'm missing?
Changed the category to Database.
<@&987246584574140416> please have a look, thanks.
so here in GreenBankMain.kt this is how I connect to the database
mongoConnect = MongoDBDatabaseConnect(this)
if (mongoConnect!!.connection != null) {
val shouldUseAsyncConnection = databaseConfigFile!!.getBoolean("should-use-async-connection")
val connectDatabaseAsync: BukkitRunnable = object : BukkitRunnable() { override fun run() { mongoConnect!!.createConnection() } }
when {
shouldUseAsyncConnection -> connectDatabaseAsync.runTaskAsynchronously(this)
!shouldUseAsyncConnection -> connectDatabaseAsync.runTask(this)
}
}
registerAll(this)
Detected code, here are some useful tools:
mongoConnect = MongoDBDatabaseConnect(this ) if (mongoConnect!!.connection != null ) {
val shouldUseAsyncConnection = databaseConfigFile!!.getBoolean("should-use-async-connection") val connectDatabaseAsync : BukkitRunnable = object : BukkitRunnable() {
override fun run() {
mongoConnect!!.createConnection() }
}
when {
shouldUseAsyncConnection -> connectDatabaseAsync.runTaskAsynchronously(this ) !shouldUseAsyncConnection -> connectDatabaseAsync.runTask(this ) }
}
registerAll(this )
here's how I connect to my database (createConnection()) and read n' write to the collection (getConnection())
This is in MongoDBDatabaseConnect.kt
override fun createConnection(): MongoClient = MongoClients.create(MongoClientSettings.builder()
.applyConnectionString(ConnectionString(greenBank.databaseConfigFile!!.getString("mongodb-connection-uri")))
.serverApi(ServerApi.builder().version(ServerApiVersion.V1).build())
.build())
override fun getConnection(): Any? {
val mongoDatabase = createConnection().getDatabase(greenBank.databaseConfigFile!!.getString("mongodb-database-name"))
return mongoDatabase.getCollection(greenBank.databaseConfigFile!!.getString("mongodb-database-collection"))
}
Detected code, here are some useful tools:
override fun createConnection() : MongoClient = MongoClients.create(MongoClientSettings.builder().applyConnectionString(ConnectionString(greenBank.databaseConfigFile!!.getString("mongodb-connection-uri"))).serverApi(ServerApi.builder().version(ServerApiVersion.V1).build()).build()) override fun getConnection() : Any ? {
val mongoDatabase = createConnection().getDatabase(greenBank.databaseConfigFile!!.getString("mongodb-database-name")) return mongoDatabase.getCollection(greenBank.databaseConfigFile!!.getString("mongodb-database-collection")) }
then i use this
val collection = (connection as MongoCollection<Document>)
to produce getters and setters for collection and type cast it as a mongodb collection
in MongoDBDatabaseConnect.kt aswell
~
~
~
and then in VaultEconomySupport.kt,
I access MongoDBDatabaseConnect.kt via GreenBankMain.kt
private val databaseConnect: MongoDBDatabaseConnect = greenBank.mongoConnect
but getCollection() (formally known as collection in kotlin) returns null for a weird reason
copied from replied message:
you're probably wondering some questions:
-
well, did you confirm the indention of the YAML files? and does the variables of mongodb-database-collection and others exist? perhaps you're using another file on accident.
I have confirmed and this is not the case. -
you probably put in the wrong collection/database, check again perhaps?
**I have tried checking multiple times, even recreating my cluster, and it doesn't work thus returning null. **
if you'd still like to check out exactly what causes this i have sent files above
please note that i'm not and I mean I AM NOT handling the exception, it's doing that on its own because VaultEconomySupport.kt returned null here
var mongoConnect: MongoDBDatabaseConnect? = null
this is mongoConnect in GreenBankMain.kt (global variable, out of methods)
and it's declared at onEnable()
mongoConnect = MongoDBDatabaseConnect(this)
this refers to the GreenBankMain.kt
so should I initialize mongoConnect when declared at the global variable, should I declare at onLoad(), or what should I do exactly?
Closed the thread due to inactivity.
If your question was not resolved yet, feel free to just post a message to reopen it, or create a new thread. But try to improve the quality of your question to make it easier to help you ๐
unresolved
Still unresolved