I am trying to insert some documents into a MongoDB database. I have also included the jar file mongo-java-driver-3.12.7 in my project build path.
My import statements are:
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.MongoClient;
The error is:
Caused by: java.lang.NoClassDefFoundError: com/mongodb/DBObject
at java.base/java.lang.Class.getDeclaredFields0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredFields(Class.java:3061)
at java.base/java.lang.Class.getDeclaredFields(Class.java:2248)....
How do I fix this? Please help me.
EDIT: After including the bson-4.1.0.jar, mongodb-driver-core-4.1.0.jar and mongodb-driver-3.9.jar (as I couldn't get the 4.1.0 one), when I run the code, I get an error in all the import statements showing The package com.mongodb is accessible from more than one module...
