Retrieving array values from mongodb using java
•
Java
I have the following code:
DBCollection collsc = db.getCollection("StudentCourses") ; BasicDBObject querysc = new BasicDBObject("StudentID",id ); DBCursor cuRSSc = collsc.find(querysc); while(cuRSSc.hasNext()) { DBObject e = cuRSSc.next(); System.out.println("You are currently registered for the following modules: ") ; System.out.println(e.get("CoursesRegistered")) ; }
Output:
You are currently registered for the following modules: [ "DigitalLogic" "OperatingSystems","FundamentalsCSE"]
However, I only want to return values from the array, that is, digital logic, operatingsystems, and fundamentals CSE I'll use these values to populate a JList Please help?
Solution
Try using
BasicDBList e = (BasicDBList) cuRSSc.next().get("CoursesRegistered");
replace
DBObject e = cuRSSc.next();
Then get the value from e.getindex (index);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码