MongoDB中的BasicDBObject拒绝取值整数

时间:2015-08-15 14:16:04

标签: java mongodb

我无法将值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);

1 个答案:

答案 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);