//the code from the link example,set registry etc
MongoDatabase db = mongoClient.getDatabase("sample_training");
MongoCollection<Grade> grades = db.getCollection("grades", Grade.class);
grades.find(); //works i get cursor of Grade instances
//THIS DOESNT WORK
Document find_command = new Document().append("find","grades");
db=db.withCodecRegistry(codecRegistry);
db.runCommand(find_command,Grade.class); //doesnt work,i get 1 Grade instance with null fields
db.runCommand(find_command); //doesnt work,i get a cursor with Documents not Grade instances
Questions
1)how to fix the runCommand to get a cursor Document where “firstBatch” will be an Arraylist of Grade instances (i need it because i am making a library)
2)when i use POJO i have perfomance penalty?
i mean at insert time it goes Grade → Document → BSON or Grade->BSON?
at read(decode) it goes BSON->Document->Grade or BSON->Grade?
I don’t know, how it can happen. But, the collection.find method returns Grade objects - I think the result you are looking for, i.e., a list of grade objects.
The runCommand:
returns a document that contains the cursor information, including the cursor id and the first batch of documents.
One way is to get the batch of documents and somehow map them individually to the Grade objects. But, thats a lot of work I think.