I am quit new to MongoDB. I have a collection with few documents inside. Below is a example for that.
{"UserID": "1", "Name": "John", "Marks":40}
{"UserID": "2", "Name": "Mark", "Marks":50}
{"UserID": "3", "Name": "Jesse", "Marks":60}
I want to get the marks of all the entries to an array to display them and to do some calculations using java. so far I have done the blow to read the document and display all the data. But I couldn't find a way to get only the "Marks" out of it.
MongoClient client = new MongoClient("localhost",27017);
DB db = client.getDB( "test_db" );
DBCollection collection = db.getCollection("AllocatedMarks");
DBCursor cursor = collection.find();
while(cursor.hasNext()) {
System.out.println(cursor.next());
}
This all I know about reading data from MongoDB using Java so far. Please help me to get only the marks field from the document to an array.
Thank you.