Ticket: User Management login

I think I misunderstood a concept on the lecture and that led to not solving the ticket problem
what I understood is when we use {upsert:true} and if the query doesnt exist it will be created instead of being undated,

now in the ticket I did this and it did not work
await sessions.updateOne(
{user_id: email},
{ $set: {user_id: email,jwt} },


as far as I understood the user_id doesn’t exist, and it will be created because we are using {upsert:true}

anyone can help here please ?! :slight_smile:

So what is the problem exactly?

Presumably a test is failing for you. So would you mind explaining which one? You should also include any specific error if any which is being shown.

Note you really should be reading the existing threads, because you’re not the first to ask.

Also note that if you are simply looking for the “inserted” documents in the collection, the unit tests delete everything they insert. So there simply won’t be anything there when the test completes. Just aim for passing test cases.

N.B You also might want to do some more reading on upserts, since the user_id is not actually required in the $set as this is implied that they key you use to “look up” the document would be automatically inserted into the new document when created.

I already fixed the problem and the tests passed :blush: thank you! and yes I did read the existing threads, I guess I should’ve just wrote a reply on an existing one, I will make sure to do that next time.

i am getting the same issue my error is regarding only login section

my input :
await sessions.updateOne(
{ user_id: email },
{ $set: { “jwt”: jwt } },
{ upsert: true },
test Error
TypeError: Cannot convert undefined or null to object

  50 |     expect(actual.success).toBeTruthy()
  51 |     const sessionResult = await UsersDAO.getUserSession(testUser.email)
> 52 |     delete sessionResult._id
     |     ^
  53 |     expect(sessionResult).toEqual(sessionUser)
  54 |   })

just give me the hint

Please check the code for getUserSession function in usersDAO.js.