使用JAVA向MongoDB中插入數據時報錯The method insert(DBObject[]) in the type DBCollection is not applicable

MONGODB JAVA驅動API文檔地址:

http://mongodb.github.io/mongo-java-driver/3.4/javadoc/

DBCollection users = db.getCollection("users");   

BasicDBObject user1=new BasicDBObject("name","zj").append("sex","male").append("age","24").append("address",new BasicDBObject("street","chaoyangzhonglu").append("number", "666"));

users.insert(user1);

報錯The method insert(DBObject[]) in the type DBCollection is not applicable for the arguments (BasicDBObject)

方法:

1.修改JAVA project的java compiler 爲1.5以上

2.users.insert(new DBObject[] {user1});

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章