I have products in my Realm database like this
[![enter image description here](https://i.stack.imgur.com/LNj7A.png)](https://i.stack.imgur.com/LNj7A.png)

I want to update my realm database based on productID, so I don't need to add another product over and over again. let say ***I want to update quantity of product that has productID = "a" to be 5***.

I have tried to write something like this.

```
        let selectedProductID = "a"
        let productsInRealmDatabase = realm.objects(Product.self)
        let productIndex = productsInRealmDatabase.index(where: {$0.productID == selectedProductID})

        if let productIndex = productIndex {

        do {

            try realm.write {
                var productRealm = productsInRealmDatabase[productIndex]
                productRealm.quantity = 5
                productsInRealmDatabase[productIndex] = productRealm // ERROR HERE
            }

        } catch {
            // error Handling
        }

    }

```

but I got error in : `productsInRealmDatabase[productIndex] = productRealm`

> 
> Error Message: Cannot assign through subscript: subscript is get-only
> 
> 
> 

so how to update realm object based on the certain property in Realm?