0

I've put a HashMap<String, Set<Long>> object into a MongoDB document under "disabled_channels" but I can't figure out how to retrieve it and turn it back into a HashMap<String, Set<Long>> object in local memory. I'm usually very good at reading in lists, individual values, etc, with something like found.getList("disabled_commands", String.class) but I'm really lost on how to approach this.

enter image description here

    MongoCollection<Document> collection = bot.getDataManager().getConfig();
    Document config = new Document("guild", guild.getIdLong());
    Document found = collection.find(config).first();
    // I get lost here
    

1 Answer 1

2

Document itself is a map implementation internally. Reference

You need to use get function on found document and cast it to Document as below

Document channels = (Document)found.get("disabled_channels")

Then you can access elements in channels using the same get method and cast it as per the need.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.