Ticket: User Management - loginUser

Greetings!

I have some issue with the lecture.
Please help me a little.
Frist of alI I only have one doc in the sessions collection. Is it oke?

Secondly my code does not work (only the first part).

It tells me the problem is in the loginUser function. I copy the loginUser code under. Can you see where is the problem? Thank you very much. :blush:
I think it will not happen nothing couse this query statement not true: { user_id: email } (couse I only have one doc where the user_id diffrent from the unit_test.email)

static async loginUser(email, jwt){
    try {
      // 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.
      //console.log(email, jwt)
      await sessions.updateOne(
        { user_id: email },
        { $set: {user_id: email, jwt: jwt}}
      )
      return { success: true }
    } catch (e) {
      console.error(`Error occurred while logging in user, ${e}`)
      return { error: e }
    }
  }

I can only imagine the problem some where else, therefore i attache some more code.

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

static async addUser(userInfo) {
/**
Ticket: Durable Writes

    Please increase the durability of this method by using a non-default write
    concern with ``insertOne``.
    */
    try {
      // TODO Ticket: User Management
      // Insert a user with the "name", "email", and "password" fields.
      // TODO Ticket: Durable Writes
      // Use a more durable Write Concern for this operation.
      await users.insertOne({name: "Magical Mr. Mistoffelees", email: "magicz@cats.com", password: "somehashedpw"})
      return { success: true }
    } catch (e) {
      if (String(e).startsWith("MongoError: E11000 duplicate key error")) {
        return { error: "A user with the given email already exists." }
      }
      console.error(`Error occurred while adding new user, ${e}.`)
      return { error: e }
    }
  }

static async logoutUser(email) {
try {
// TODO Ticket: User Management
// Delete the document in the sessions collection matching the email.
await sessions.deleteOne({ user_id: email })
return { success: true }
} catch (e) {
console.error(Error occurred while logging out user, ${e})
return { error: e }
}
}

static async getUserSession(email) {
try {
// TODO Ticket: User Management
// Retrieve the session document corresponding with the user’s email.
return sessions.findOne({ user_id: email })
} catch (e) {
console.error(Error occurred while retrieving user session, ${e})
return null
}
}

Have a real nice holiday!
Thank you for your prompt reply!
:blush:

I get it. I wasnt use { upsert:true}…