我无法将值30添加到关键年龄我收到错误消息:类型put(String, Object)
中的方法BasicBSONObject
不适用于参数(String, int)
。也适用于newDate
方法
BasicDBObject document = new BasicDBObject();
document.put("name", "baja");
document.put("age", 30);
document.put("createdDate", newDate());
table.insert(document);
答案 0 :(得分:0)
private static MongoDatabase db;
private static final String collectionName = "tweets";
final MongoClientURI uri = new MongoClientURI(DB_URL);
//example mongodb://localhost:27017/databaseName
final MongoClient client = new MongoClient(uri);
db = client.getDatabase(uri.getDatabase());
Document document = new Document();
document.put("name", "baja");
document.put("age", 30);
document.put("createdDate",new Date());
db.getCollection(collectionName).insertOne(document);