From my Java application, I have stored the values in mongoDB in ArrayList(set of Java objects). How can I retrieve the data from DBObject
I am storing the data in mong
You generally use an ORM tool for that (though it wouldn't be meaningful to call it ORM in the case of a non relational database).
There are several such tools. I like spring-data, which hides a lot of boiler plate code for you and gives you a simple, clean syntax. Something like this:
@Repository
public class UserRepositoryImpl implements UserRepository {
private MongoTemplate mongoTemplate;
@Autowired
public UserRepositoryImpl(MongoTemplate mongoTemplate) {
this.mongoTemplate = mongoTemplate;
}
@Override
public User findsUserByUsernameAndPassword(String userName, String encodedPassword) {
return mongoTemplate.findOne(query(where("userName").is(userName).and("encodedPassword").is(encodedPassword)), User.class);
}
}
With the User
class defined as:
@Document(collection = "users")
public class User {
private String userName;
private String encodedPassword;
// snip getters and setters
}