mongodb – Java Driver – Fetch Collection data with condition

To get data from testcollection collection in testdb database where name=dev

import org.bson.Document;
import com.mongodb.BasicDBObject;
import com.mongodb.MongoClient;
import com.mongodb.ServerAddress;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.MongoDatabase;

MongoClient mongoClient = new MongoClient(new ServerAddress("localhost", 27017));
MongoDatabase db = mongoClient.getDatabase("testdb");
MongoCollection<Document> collection = db.getCollection("testcollection");

BasicDBObject searchQuery = new BasicDBObject();

MongoCursor<Document> cursor = collection.find(searchQuery).iterator();  
try {
    while (cursor.hasNext()) {
} finally {

if you want to reproduce, please indicate the source:
mongodb – Java Driver – Fetch Collection data with condition - CodeDay