MongoDB updates with java driver version 3.0

I port my applications to MongoDb 3.0.2. I have no problem with inserts, finding and deleting. But problems with updating. Especially with eq() .

In this sentence:

 coll.updateOne(eq("_id", id), new Document("$set", new Document("name", name))); 

The variable id defined by ObjectId . Eclipse gives me an error:

The eq (String, ObjectId) method is undefined for type SystemDAO (my java class).

What am I doing wrong? I followed the examples in the Mongo java driver docs.

+6
source share
1 answer

you need to import the static eq method from com.mongodb.client.model.Filters package.

add this infront of your class to your other import:

 import static com.mongodb.client.model.Filters.*; 

In Eclipse, it should quickly fix importing the correct package if you click on an error. But for static imports, this does not work all the time.

+7
source

Source: https://habr.com/ru/post/986131/


All Articles