我正在尝试使用 java 将数据插入 MongoDB,但在尝试编译代码时出现错误。我不知道是什么导致了错误。我想添加新书条目。
error message:
required: String,Object
found: List<Document>
reason: actual and formal argument lists differ in length
UseMongoDB.java:61: error: method put in class Document cannot be applied to given types;
book.put(publishers);
private MongoCollection<Document> books = db.getCollection("books");
void insertanewbook() {
Document book = new Document();
book.put("title", "test");
book.put("category","test");
book.put("price",12.3);
List<Document> authors = new ArrayList<Document>();
Document author = new Document();
author.put("first_name","jonn");
author.put("last_name","james");
author.put("country","t");
author.put("website","www.test.com");
authors.add(author);
book.put(authors);
List<Document> publishers = new ArrayList<Document>();
Document publisher = new Document();
publisher.put("publish_date",new Date());
publisher.put("name","test");
publisher.put("country","test");
publisher.put("website","www.test.com");
publishers.add(publisher);
book.put(publishers);
books.insertOne(book);
}
摇曳的蔷薇
相关分类