M220N Ticket User Management

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?

Hi @David_Thompson :wave:,

You can pass the update options as below:

new UpdateOptions{optionKey = optionValue}.

Therefore, in this case your update options would look something like:

new UpdateOptions{IsUpsert = true}

I hope it helps.

In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer

Thanks for your recommendations… One more question though. In VS… How do I know when to use () or when to use {}?

What I have observed so far is, whenever you want to set the property of an object or call the constructor function you have to use the {} and in places when you want to pass values to a function you should use ().

In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer