Currently utilizing Mongoose for communication with MongoDB. Running into issues while attempting to execute certain operations.
The database contains a collection named USERS, characterized by the following schema:
{username: 'user1', id: 1, lastName: 'ln1' }
{username: 'user2', id: 0, lastName: 'ln2' }
The 'id' field can possess values of 0, 1, 2, or 3.
I am looking to add a new object based on the following conditions:
- If the username already exists and has an id of 1, update the details.
- If the username does not currently exist, create a new entry without verifying the id field.
- If the username exists but has an id of 0, 2, or 3 (non-1 values), refrain from making any updates or adding the user to the collection, maintaining the existing user's data as they failed to be added to the database.
Your assistance is greatly appreciated.