#MongoDB implementation
1 messages · Page 1 of 1 (latest)
Yeah ive made applications with mongo before just never with java
right perfect
so in Java You use a module called mongo-java-driver in case using Maven
good
let starts with the basic
I'm My case i always use mongo with uris for commection
Yeah I have it setup and connected, I just need help with like data part
Oh okay, sorry i Will explain that
package me.tls.rpg.common.data;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import me.tls.rpg.common.data.player.PlayerData;
import org.bukkit.plugin.java.JavaPlugin;
public class DatabaseManager {
private final MongoDatabase database;
private final MongoCollection<PlayerData> playerDataCollection;
public DatabaseManager(JavaPlugin plugin, String URI, String database, String collection) {
try (MongoClient client = MongoClients.create(URI)) {
plugin.getLogger().info("=> Connection to Database Successful");
this.database = client.getDatabase(database);
this.playerDataCollection = this.database.getCollection(collection, PlayerData.class);
}
}
public MongoDatabase getDatabase() {
return this.database;
}
public MongoCollection<PlayerData> getPlayerDataCollection() {
return this.playerDataCollection;
}
}
this is my DatabaseManager right now, when I did previous work with mongo it was in go so there was no OOP so i think this approach is very bad in java but I dont know
Yes ofc for a document orianted database
Not that I know of
I just dont know how to layout my data- and how to efficently update, insert, remove ect as needed
I have an example json if you want me to send that?
Yeah, I have the thing mapped out and how I think it would best work. I just dont know the best way to implement it as its a huge data structure
a) As usual when You work with databases You should always use them async
b) Can also implement catching systems, like Guava cache for example, Caffeine or Even use a HashMap / List
ugh i hate async
oh well Big issue hajaja
yeah lol
You Will have yo love it
because is our Best friend
specially when doing working with things that has connections to remote things
okay
In My case i take approch of creating a Collection for a single reposability
where users Collection just store users info, not his punish
Yeah thats fair
I store punish un another Collection
Yeah I would probably do that
and in user Collection link each punish object ID to an array of punish ids
thats is most applied if You worked before with relational dbs like MySQL for example
Yeah I have
those get super confusing though with asmuch data as you need for an RPG
yeah that why You should first design the diagram of the db. And then start coding
I use lucid chart for designing the dbs models
Yeah, do you know any plugins that use mongodb that I could look at for examples?
The ones i know most of them uses bad practices in general. I wouldnt like to recommend something which has bad practices