Answer Posted / Irshad Ali
To retrieve data from MongoDB using Java, you can use a library called MongoDB Java Driver. Here's a basic example of how to connect and find documents:
```java
import com.mongodb.*;
MongoClient mongoClient = new MongoClient("localhost", 27017);
DB db = mongoClient.getDB("test"); // Your database name
DBCollection collection = db.getCollection("users"); // Your collection name
DBCursor cursor = collection.find();
while (cursor.hasNext()) {
System.out.println(cursor.next());
}
```
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers