我有这个代码:
public class UpdateShoe {
MongoClient mongoClient = MongoClients.create();
MongoDatabase db = mongoClient.getDatabase("MirandasShoes");
MongoCollection<Document> collection = db.getCollection("Shoes");
MongoCursor<Document> cursor = collection.find().iterator();
public void UpdateShoe(Shoe sfilter, Shoe snew) {
Document sfilterdoc = new Document();
sfilterdoc.append("_id", sfilter.getId());
sfilterdoc.append("Name", sfilter.getName());
sfilterdoc.append("Brand", sfilter.getBrand());
sfilterdoc.append("Type", sfilter.getType());
sfilterdoc.append("Color", sfilter.getColor());
sfilterdoc.append("Size", sfilter.getSize());
sfilterdoc.append("Price", sfilter.getPrice());
Document snewdoc = new Document();
snewdoc.append("Name", snew.getName());
snewdoc.append("Brand", snew.getBrand());
snewdoc.append("Type", snew.getType());
snewdoc.append("Color", snew.getColor());
snewdoc.append("Size", snew.getSize());
snewdoc.append("Price", snew.getPrice());
this.collection.updateOne(sfilterdoc, snewdoc);
}
Run Code Online (Sandbox Code Playgroud)
}
当我点击更新按钮时,它抛出异常,显示无效的 BSON 字段名称名称。在智能感知中,它指定参数必须是 bson 并且我正在使用文档,但在在线文档中主要使用文档,那么为什么它会抛出异常,我的代码中有什么问题吗?
这是我点击更新按钮时的控制台输出:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Invalid …Run Code Online (Sandbox Code Playgroud)