Ticket User Preferences

I am very confused about where the data “prefs” is supposed to go. Is there a field in “users” that can hold that data?

1 Like

@harriettxing

The key for preds is preferences.

@harriettxing
Did you manage to make it run?
I’m stucked here

@nayamama: I think the key is preferences not preference.

Could you please confirm?

@ksp585

Yes, you are right, my mistake.

     MongoDB Enterprise mflix-shard-0:PRIMARY> db.users.findOne({preferences: {$exists: true}})
    {
            "_id" : ObjectId("5aabfe4d55593fd765402dfc"),
            "name" : "623fzap5x",
            "email" : "fdfnhnksq@mcavt.5xu",
            "password" : "$2b$12$H94MePYQVZehoTVu0zvARu5rFI7qnV1EwGR7w280761pBxtrehzte",
            "preferences" : {
                    "favorite_fruit" : "watermelon",
                    "favorite_number" : "42"
            }
    }

Q Yang

1 Like

This gave me an idea that a preference can be added to the record.

my bad: I was running the “test_valid_user_preferences” test and trying to understand with “test_invalid_user_should_not_have_preferences”.


I modified the db.users.update_one(), and then running the test: test_invalid_user_should_not_have_preferences. Test is getting passed, but when I querying the document, preferences object are not getting inserted as assigned in the test case. I am aslo not sure why name & password fields are populated when update_one is only setting email with upsert as True.

preferences = {
“color”: “green”,
“favorite_letter”: “q”,
“favorite_number”: 42
}

MongoDB Enterprise mflix-shard-0:PRIMARY> db.users.find({email: "foobaz@bar.com"}).pretty()
{
“_id” : ObjectId(“5c0561ec5d7f0ed99fa5f312”),
“name” : “foo”,
“email” : "foobaz@bar.com",
“password” : “foobar”,
“preferences” : {
“favorite_cast_member” : “Daniel Day-Lewis”,
“favorite_genre” : “Drama”,
“preferred_ratings” : [
“R”
]
}
}