I'm just switching from MySQL to MongoDB and it's a little confusing. We have our database stored in MongoDB and using Java-Selenium in the front end. I am trying to retrieve just one single data from the database. The code below retrieves all the data present in the database:
DBCursor cursor = dbCollection.find();
while(cursor.hasNext())
{
int i=1;
System.out.println(cursor.next());
i++;
}
This is my database lets say:
{
"name" : "Su_123",
"email" : "test@gmail.com",
"_id" : ObjectId("12345656565656")
}
I want to retrieve just the email field (test@gmail.com) from the document where _id = ObjectId("12345656565656")
and store this in a String field.
How do I go about coding this? find()
retrieves the entire row.