M220-Ticket:User Management

Hi, anyone can help? I think I did correct code changes.

● User Management › it allows a user to login

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 |   })
  55 |

<< My Code >>

(1) TODO

// TODO Ticket: User Management
// Retrieve the user document corresponding with the user's email.
return await users.findOne({ email: email })

(2) TODO

// TODO Ticket: Durable Writes
// Use a more durable Write Concern for this operation.
await users.insertOne({ name:userInfo.name, email:userInfo.email, password:userInfo.password })

(3) TODO
// TODO Ticket: User Management
// Use an UPSERT statement to update the “jwt” field in the document,
// matching the “user_id” field with the email passed to this function.
await sessions.updateOne(
{ user_id: email },
{ $set: { jwt: jwt } },
{ updset:true}, // , doesn’t matters
)

(4) TODO
// TODO Ticket: User Management
// Delete the document in the sessions collection matching the email.
await sessions.deleteOne({ user_id: email })

(5) TODO
// TODO Ticket: User Management
// Retrieve the session document corresponding with the user’s email.
return sessions.findOne({ user_id: email })

Vincent

[solved] - typo > “upsert”

  await sessions.updateOne(
      { user_id: email },
      { $set: { jwt: jwt } },
      { upsert:true},  ==> correct typo
  )

Hi @Ukkyu_Kang,

Welcome to MongoDB Community Forum.

We are glad that your issue is resolved.

Feel free to reach out if you have any doubts and questions.
We will be happy to help.

Happy Learning…:slightly_smiling_face:

Thanks
Kushagra