Update a document using an index

Can I update a document using an index without needing to do a GET operation? Currently the way I do it is this:

  1. Get the record based on the index.
  2. Get the ref from the result.
  3. Update document using the retrieved ref.

As you can see, this is:

  1. Slower – because it will have to get the record first before updating it.
  2. More costly – because it does 1 get and 1 update.

Two ways to get a single item from a Set. Both cost the same read ops. You cannot escape a read operation for fetching data.

  1. You can use Get, which will actually fetch the first doc. Costs 1 Read Op, 1 Write Op.
  2. You can Paginate and select the first item, which will be the Ref. Costs 1 Read Op, 1 Write Op.

So, no, not more costly.

I think its a good question of what is actually going on in the background, though. It’s come up other places in the forums of how to get a single value out of an index, but the performance (time) difference has never come up.

Select('ref', Get(Match(/* ... */)))

// Same result as

Select(0, Paginate(Match(/* ... */)))

Thanks for the assistance @ptpaterson :bowing_man: