UserPreferences compile error [Solved]

Hello there, I have below implementation which I think is correct, however the test is failing to compile:

public boolean updateUserPreferences(String email, Map<String, ?> userPreferences) {
//Set The Filter criteria
Bson queryFilter = new Document(“email”, email);

// retrieve the required user
User userToUpdate = usersCollection.find(queryFilter).iterator().tryNext();

// update the field that needs changes using set and updateOne
//This is line 204

I am getting below exception:

[INFO] -------------------------------------------------------------
[INFO] -------------------------------------------------------------
[ERROR] /C:/University/M220J/mflix-java/mflix/src/main/java/mflix/api/daos/[204,34] cannot find symbol
symbol: method set(java.lang.String,java.util.Map<java.lang.String,capture#1 of ?>)
location: class mflix.api.daos.UserDao
[INFO] 1 error

Any help here?

Thanks a lot in advance,

Please do not post your questions in more that one thread.

steevej wrote:
“This is not an exception, this is a compilation error. The error tells you that you do not use set() correctly. You may call set() with the same variable name, userPreferences, but it does not mean that userPreferences has the same type”

Steevej, first of all, thanks so much for replying!!!
Steevej, I know that the compilation is failing due to a data type mismatch. However, I tried changing userPreference parameter to Map<String, Object>, Map<String, String> and event to just String but basically getting same compilation error. I checked and the data type for this parameter is Map<String, ?> userPreferences just like we have it, and it is working there.

I also try Map<String, String> preferences = userPreferences and then use the variable preferences in the set(). still no working. I did not know that we needed to change the data type for userPreferences. What am I missing here?

I did not have to change the data type of userPreferences. However, I am not using the builders provided. I would check which static import imports the set method. You might be missing some imports because it looks like UserDao.set() is called. And I am not sure this is correct.

I don’t use builders, because I prefer my code to be closer to the shell syntax using straight org.bson.Document.

Thanks steevej, you were right, the method was not “set”. it was actually “setPreferences” and is implemented in the under the model directory.

Thanks again!

1 Like