Search code examples
react-nativerealm

Updating an object with Realm without a Primary Key


In my React-Native app, I need to update some objects but I can't do like the tutorial :

realm.write(() => {
 // Create a book object
 realm.create('Book', {id: 1, title: 'Recipes', price: 35});

 // Update book with new price keyed off the id
 realm.create('Book', {id: 1, price: 55}, true);
});

Because my objects don't have a primary key (and i don't want them to have primary key)

There is my try :

this.state.realm.write(() => {
  this.state.realm.create('Bills', {type: this.state.billType,
  creditor: this.state.billCreditor, month: this.state.billMonth,
  year: this.state.billYear, price: this.state.billPrice}, true);
});

But this try obviously create an another object ^^

Is someone have an idea for my problem please? Thanks for all =)


Solution

  • Finally, I used UUID as Primary key ^^"

    https://www.npmjs.com/package/react-native-uuid