I'm a starting to use MongoDb and developping a small web application that connect to this Mongo Database. I have a DAO with a method to find a user from the db according to the email address assigned to the user. Each user should have a unique email address so I can assume I'll get only one document. How can then convert the DBObject to a User entity?
Here my code:
@Override
public User findUserByEmailAddress(String email) {
DB db=MongoHelper.getDb();
BasicDBObject query = new BasicDBObject();
query.put("email", email);
DBCollection users=db.getCollection("users");
DBCursor cursor = users.find(query);
DBObject user=cursor.next();
//Code to convert the DBObject to a User and return the User
}
Thank you very much in advance!