DBCollection collection = db.getCollection("user"); DBObject object = new BasicDBObject(); object.put("name", "aaa"); object.put("age", 11); collection.save(object); System.out.println(object.get("_id"));