I'm migrating my aplications to MongoDb 3.0.2. I have no problems with inserts, finds and deletes. But,Problems with the update. Specially with the eq()
.
In this sentence:
coll.updateOne(eq("_id", id), new Document("$set", new Document("name", name)));
The id
variable is defined ObjectId
. Eclipse gives me an error:
The method eq(String, ObjectId) is undefined for the type SystemDAO (my java class).
What am I doing wrong? I followed the examples in the Mongo java driver documents.
you need to import the static method eq
from the package com.mongodb.client.model.Filters
.
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. But for static imports this does not work all the time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With