Hood.ie Find and Update Data

58 views Asked by At

Just started using Hood.ie - have a question with finding and updating data.

I have a type called 'who' within which i have stored a 'personId' and 'time'. What i want to do is search 'who' for 'personId' I specify then update record which is empty.

So i can do basic updates like

hoodie.store.update('whosin', clicked_id, { timeOut: Date() });

but how do i do the more complicated one with hood.ie as above - something roughly like:

hoodie.store.update('whosin', personID = clicked_id, { timeOut: Date() WHERE timeOut = "" });
1

There are 1 answers

1
Gregor On BEST ANSWER

If I understand you correctly, you want to set the timeOut property only if it's not set yet. You can achieve that by passing an updateFunction, see the 2nd example here: http://docs.hood.ie/en/techdocs/api/client/hoodie.store.html#storeupdate

In your case that would be

hoodie.store.update('whosin', clicked_id, function (object) {
  if (!object.timeOut) object.timeOut = Date()
});