I think itβs easiest to just change your code to use a document, not BasicDBObject.
So change
BasicDBObject doc = new BasicDBObject("name", "john") .append("age", 35) .append("kids", kids) .append("info", new BasicDBObject("email", " john@mail.com ") .append("phone", "876-134-667"));
For
import org.bson.Document; ... Document doc = new Document("name", "john") .append("age", 35) .append("kids", kids) .append("info", new BasicDBObject("email", " john@mail.com ") .append("phone", "876-134-667"));
and then paste into the collection
coll.insertOne(doc);
You will need to change other bits of code to work with MongoDB 3+
MongoDatabase and DB MongoCollection vs DBCollection
James adrian
source share