P
P
P_Alexander2018-05-04 10:47:45
Java
P_Alexander, 2018-05-04 10:47:45

How to bring from Document to the object I need?

Hello, how can I lead from Document to the object I need?
There is a Movies model
From the database, I get the Mongo Collection of the Document type

MongoCollection<Document> mongoCollection = database.getCollection("movies");

and when I sort through the entire collection, I need to convert the document into a Movie, of course, you can get it from the document by key, but what if there are 1000 keys in the document? that everything is written by hand? If there is some way?
MongoCursor<Document> cur = mongoCollection.find().iterator();
        while (cur.hasNext()){
         System.out.println(cur.next().toString());
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2018-05-04
@zolt85

Make a constructor in Movie, to which to pass Document.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question