当我尝试将BasicDBObjectBuilder插入集合
时,我收到以下错误引起:java.lang.ClassCastException:com.mongodb.BasicDBObject无法强制转换为com.mongodb.BasicDBObjectBuilder
MongoClient mongo = new MongoClient( "xxx.xxx.x.x" , 27017 );
MongoDatabase db = mongo.getDatabase("hello"); //create database
MongoCollection<BasicDBObjectBuilder> collbuild = db.getCollection("newcoll", BasicDBObjectBuilder.class);
BasicDBObjectBuilder collbuilder = BasicDBObjectBuilder.start()
.add("name","joe")
.add("dob", "12/12/12")
.add("country", "Utopia");
collbuild.insertOne((BasicDBObjectBuilder) collbuilder.get()); // passing BasicDBObjectBuilder into a BasicDBObjectBuilder collection?
我以为我将BasicDBObjectBuilder传递给BasicDBObjectBuilder集合。我知道如何使用BasicDBObject,但我想尝试这种方法,因为我是编程新手。有人可以澄清吗?
已更新
似乎我试图使用insertOne这是一个BasicDBObject函数。那么将BasicDBObjectBuilder传递给BasicDBObjectBuilder集合需要什么呢?