Cannot fetch data from mongo with java : i trying to fetch some data from mongo with netbeans but i get this error

    java.lang.IllegalStateException: state should be: open

I have tried everything. This is the line that crashes:

    Document doctor = doctors.find(new Document("doctor_name", DocName.getText())).first();

Connects successfully and the collection exists. Dunno what else to do