The functionality I want to achieve:
On the frontend I have the list of all the owners in with checkboxes.. The added owners are already checked.. How can I achive that if I uncheck some owner ID and check like 2 new owners, so I remove the unchecked owner and add the new "checked" one.

I have a user model:

```
const UserSchema = new mongoose.Schema({
  email: { type: String, required: true, min: 6, max: 255 },
  password: { type: String, required: true, min: 4, max: 1024 },
  role: { type: String, required: true, default: "User" },
  owners: [
    {
      type: Schema.Types.ObjectId,
      ref: "Owners",
      required: false,
    },
  ],
});

```

Every usser has an array of owners [![enter image description here](https://i.stack.imgur.com/UJQxy.png)](https://i.stack.imgur.com/UJQxy.png)

I add owner to the specific user with this query PUT METHOD:

```
exports.addOwnerToUser = async (req: Request, res: Response) => {
  try {
    let ObjectID = require("mongodb").ObjectID;
    const mongoose = require("mongoose");

    const user = {
      email: req.body.email,
      ownerId: req.body.ownerId,
    };

        const updatedUser = await User.findOneAndUpdate(
  { _id: req.params.userId, owners: { $ne: req.body.ownerId } },
  { $push: { owners: { $each: req.body.ownerId } } },
  { new: true, useFindAndModify: false }
);

    res.status(201).json({ sucess: true, msg: "User updated sucessfully" });
  } catch (err) {
    res.status(404).json(err);
  }
};

```

**2.)** How can I achive that, if I on the frontend UNCHECK the owner, that it gets removed from owners array?