This Post explains - How To Fix - Database Access Error in MongoDB. Sometimes (if you are using older versions of MongoDB while the source code uses latest version systax , you might face issue while connecting Database Objects. We will discuss one such example below.
"Error:(21, 51) java: incompatible types: com.mongodb.DB cannot be converted to com.mongodb.client.MongoDatabase"
final MongoClient client = MongoClients.create(uri);
/\*
Prereq: Create collections. CRUD operations in transactions must be on existing collections.
\*/
client.**getDatabase**("mydb1").getCollection("foo")
.withWriteConcern(WriteConcern.MAJORITY).insertOne( new Document("abc", 0));
client.**getDatabase**("mydb2").getCollection("bar")
.withWriteConcern(WriteConcern.MAJORITY).insertOne( new Document("xyz", 0));
Hope this Post helps you To Fix - Database Access Error in MongoDB
Additional Read -