I'm using Mongodb Realm. I know it is possible to 'createOrUpdate' in realm by using the primary key i.e If the primary key doesn't exists create a new object, If it does update the object.
Something like
realm.write(() => {
// Create a book object
realm.create('Book', {id: 1, date: '12-12-2020', price: 35});
// It will update the price but won't create a new object since the id is the same
realm.create('Book', {id: 1, date: '12-12-2020', price: 55}, 'modified');
});
The realm docs says that
If your model class includes a primary key, you can have Realm intelligently update or add objects based off of their primary key values. This is done by passing true as the third argument to the create method:
this can be found here https://docs.mongodb.com/realm-legacy/docs/javascript/latest/#creating-and-updating-objects-with-primary-keys
NOW, I want to update the Object based on a different field(key) apart from the primary key and On this case it is the date field This is to say that, If the date doesn't exist, create a new object/entry but it it does, just update the price.
How do I do this with realm?