This is a REALLY frustrating lab. I understand that VS cannot be taught, but were there is a lot of confusion for me is in the writing and reading of data. I understand how to build basic queries, but this User Management Ticket, is really confusing.
The course only covers BASIC reading and writing of data. This ticket involves updating 5 different methods… I got the first two… but in the login method, I am really confused.
I understand the .jwt token and I can see the need to update it in the sessions collection with the user.authToken… But I am confused on the ticket writeup.
I believe I got the update correct but I don’t understand the last portion of the directions that tell me if the session doesn’t exist, allow MongoDB tdo create a new one by passing the IsUpsert update option… This is NEVER even talked about in the lecture. What is meant by this?
// TODO Ticket: User Management // Locate the session object in the `sessions` collection by // matching the "user_id" field with the email passed to this function. // Then update the Session.UserId and Session.Jwt properties, // setting the former to the email and the latter to the // user.AuthToken that is passed in from the Controller. // // If the session doesn't exist, allow MongoDB to create a // new one by passing the IsUpsert update option.
This is the query I built so far
await _sessionsCollection.UpdateOneAsync( new BsonDocument(user.Email, user.AuthToken), Builders<Session>.Update.Set(t => t.UserId, user.Email).Set(t => t.Jwt, user.AuthToken)); // new UpdateOptions(...));
Where I am not certain is the new UpdateOptions (…). How do I pass in the IsUpsert option?