How i can retrieve MongoDB data inTextboxes through javadriver?
mongodb, textbox
Solution
The following code fragment shows how to extract the individual fields of a document when you iterate over the results of a query. You could, if you wanted, take each field and put it in a textbox of a GUI.
The complete code sample is here: https://gist.github.com/3087822
private static void queryAndDisplayStudents(DBCollection students)
{
// Get all students (no query criteria).
DBCursor cursor = students.find();
// Iterate over the students.
while (cursor.hasNext())
{
// Display each student.
DBObject student = cursor.next();
// Get the individual fields of the student document.
// These individual fields could, for example,
// be put in text fields of a GUI.
String name = (String) student.get("Name");
Number sid = (Number) student.get("SID");
String university = (String) student.get("University");
// Given that we are not actually building a GUI,
// just display the fields on the command line.
System.out.printf("Student name: %s, SID: %d, University: %s%n",
name, sid, university);
}
}
Problem
How can I retrieve MongDB data and load in textboxes using javadriver? I tried the following code to show data, but I want to get the data in textboxes: ``` BasicDBObject doc = new BasicDBObject(); doc.put("Name", v2); doc.put("SID", n4); doc.put("University", v4); DBCursor Cur = coll.find(doc); System.out.println(Cur); ```