'Parsing bson.Document in Java

I am trying to connect MongoDB from my java code, then query it and store it in a variable of type Document like this:

    MongoClient client = MongoClients.create();
    MongoDatabase db = client.getDatabase("calculate");
    MongoCollection col = db.getCollection("calculate");
    Document profile = (Document)col.find(new Document("op1", op1).append("op",op).append("op2",op2)).first().toJson();

Now the profile variable, when printed, prints {"op":"+", "op1":"12", "op2":"13"}. How do I get value, given the key in java jsonObject? Eg: profile.op or profile["op"] should be "+" w.r.t. python syntax?

.getString() method doesn't seem to be working.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source