I am using mongodb java driver 3.0.2 (I tried 3.0.1 and 3.0.0 but I get the same error).
This is the error that I get: The type org.bson.Document cannot be resolved. It is indirectly referenced from required .class files
It happens on the second line of the following code:
MongoDatabase db = mongoClient.getDatabase("db");
db.getCollection("");
As I understand the second line uses code that exists in org.bson.Document and it cant find it. But where can I find it?
************** EDIT ************ I know added the bson jar and it has the org.bson package BUT there is not org.bson.Document class inside this package...
The MongoDB Atlas SQL JDBC Driver provides SQL connectivity to MongoDB Atlas for client applications developed in Java. See the Atlas SQL Documentation for more information. MongoDB Atlas SQL JDBC is a JDBC Type 4 driver compatible with the JDBC 4.2 specification.
All features are supported.
The JDBC driver for MongoDB allows SQL queries on MongoDB for any software that supports JDBC. SQL support includes functions, expressions, aggregation, and joins including for collections with nested objects and arrays. See the features and SQL examples supported by the JDBC driver for MongoDB.
I believe you have downloaded the MongoDB-Driver for Java, and not the Mongo-Java-Driver.
Easiest way is to download the mongo-java-driver-3.x.x.jar library, available at http://mongodb.github.io/mongo-java-driver/
It contains the following packages:
If you install the MongoDB driver only , then you need to download BSON Library separately.
Document class exist since from 3.0.0 and not in MongDB jar, it's in BSON jar file. You can download from https://oss.sonatype.org/content/repositories/releases/org/mongodb/bson/3.0.2/bson-3.0.2.jar
Reference:
public class Document extends Object implements Map, Serializable, Bson A representation of a document as a Map. All iterators will traverse the elements in insertion order, as with LinkedHashMap. Since: 3.0.0
http://api.mongodb.org/java/3.0/org/bson/Document.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With