$min

Update records by setting the value of a numeric column to the minimum of its current value and a specified number. The $min method works similarly to Math.min(), which returns the smallest of two values. It is used to ensure that the column’s value doesn’t exceed a given minimum threshold. For example, if the current value is greater than the specified number, it will be updated to the specified number.

await Member.$update({
    $where: { 
        age: { 
            $eq: 16 
        } 
    },
    $update: {
        $min: {
          age: 1
        }
    }
});

Last updated