#My plugin will NOT START (and I suspect it's MongoDB) and I don't know why

1 messages ยท Page 1 of 1 (latest)

feral dove
#

Details below

feral glenBOT
#

<@&987246584574140416> please have a look, thanks.

feral glenBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

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.

feral dove
#

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:

  1. 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.

  2. 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.

feral glenBOT
feral dove
#

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

feral glenBOT
#

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 ๐Ÿ‘

feral dove
#

unresolved.
is there something i'm missing?

feral glenBOT
#

Changed the category to Database.

#

<@&987246584574140416> please have a look, thanks.

feral dove
#

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)
feral glenBOT
# feral dove so here in GreenBankMain.kt this is how I connect to the database ```kt mongoCon...

Detected code, here are some useful tools:

Formatted code
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 )
feral dove
#

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"))
    }
feral glenBOT
# feral dove here's how I connect to my database (createConnection()) and read n' write to th...

Detected code, here are some useful tools:

Formatted code
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")) }
feral dove
#

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

feral dove
# feral dove Reading this, my connection returns null from vault, and I severely suspect that...

copied from replied message:

you're probably wondering some questions:

  1. 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.

  2. 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. **

feral dove
feral dove
# feral glen Detected code, here are some useful tools:
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?

feral glenBOT
#

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 ๐Ÿ‘

feral dove
#

unresolved

feral dove
#

Still unresolved