Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB updates with java driver version 3.0

Tags:

java

mongodb

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.

like image 788
Augusto Avatar asked Apr 28 '15 11:04

Augusto


1 Answers

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.

like image 99
Simulant Avatar answered Sep 29 '22 11:09

Simulant