Chapter 3: User Preferences

Hi all,
I have an headscratch and I am wondering if someone can help mw with this ticket: the “status” check fails (preferences weren’t saved correctly) but the unittest succeed. I really cannot figure out the reason. My implementation of the method is below:

            var filter = Builders<User>.Filter.Eq( y => y.Email , email);
            var updateFields = Builders<User>.Update.Set(y => y.Preferences, preferences);
            var opts = new UpdateOptions { IsUpsert = false };
            updateResult = await _usersCollection.UpdateOneAsync(filter, updateFields, opts, cancellationToken);

Hi @Andrea_Agostini, :wave: .
Can you try again by replacing your filter with the following?

var filter = new BsonDocument("email", email) 

Hopefully, it will fix the issue.

In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer

Hi,
thank you for your answer, but the modification that you have proposed doesn’t work; I get the same result.

In my understnding your filter and mine are equivalent; am I wrong?

Regards,
Andrea

Hi @Andrea_Agostini, :wave: .
Can you try again by replacing your updateFields with the following?

Builders<User>.Update.Set("preferences", preferences)

Hopefully, it will fix the issue.

In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer

Hi @SourabhBagrecha ,
thank you very much for the suggestion, but it doesn’t work. I have applied both your suggestions.

Regards,
Andrea

Hi @Andrea_Agostini, that’s really strange.
However, I have to take a look at the other parts of your code, I am sending you a DM, please check your inbox.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.