在我的 Java 应用程序中,我将 mongoDB 中的值存储在 ArrayList(Java 对象集)中。如何从 DBObject 检索数据
我将数据存储在 mongoDB 中,如下所示:
{ "students" : [{"firstName" : "Jesse", "lastName" : "Varnell", "age" : "15", "gender" : "M" }, { "firstName" : "John", "lastName" : "Doe", "age" : "13", "gender" : "F"}] }
我有学生的Java对象,例如:
public class Student {
public String firstName;
public String lastName;
public String age;
public String gender; // M, F
}
我正在从 mongoDB 中检索数据,例如:
BasicDBObject query = new BasicDBObject();
query.put("user", username);
DBCursor cursor = theCollection.find(query);
while (cursor.hasNext()) {
DBObject theObj = cursor.next();
//How to get the DBObject value to ArrayList of Java Object?
}