[英]MongoDB updates with java driver version 3.0
I'm migrating my aplications to MongoDb 3.0.2. 我正在将我的应用程序迁移到MongoDb 3.0.2。 I have no problems with inserts, finds and deletes.
我没有插入,查找和删除的问题。 But,Problems with the update.
但是,更新问题。 Specially with the
eq()
. 特别是与
eq()
。
In this sentence: 在这句话中:
coll.updateOne(eq("_id", id), new Document("$set", new Document("name", name)));
The id
variable is defined ObjectId
. id
变量定义为ObjectId
。 Eclipse gives me an error: Eclipse给了我一个错误:
The method eq(String, ObjectId) is undefined for the type SystemDAO (my java class).
对于SystemDAO (我的java类) 类型,方法eq(String,ObjectId)是未定义的 。
What am I doing wrong? 我究竟做错了什么? I followed the examples in the Mongo java driver documents.
我按照Mongo java驱动程序文档中的示例进行操作。
you need to import the static method eq
from the package com.mongodb.client.model.Filters
. 您需要从
com.mongodb.client.model.Filters
包中导入静态方法eq
。
add this infront of your class to your other imports: 将此类前面的内容添加到其他导入中:
import static com.mongodb.client.model.Filters.*;
In Eclipse it should give a quick-fix to import the right package if you do a mouse over on your error. 在Eclipse中,如果您将鼠标悬停在错误上,它应该快速修复以导入正确的包。 But for static imports this does not work all the time.
但对于静态导入,这并不是一直有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.