Is there any way to convert an array of Refs to a Set?
Use case:
If a client sends an array of ids or Refs for an operation, it could be useful to use Intersection and/or other Set operations for that array with Sets in the DB.
This can kinda be done now, but it requires reading the Set and mapping to an array. If the user provided array is much smaller than the Set, then paginating the whole Set would be very wasteful.
I suppose you could use an Index by Ref and then Union those. This might actually be okay for really small user input, but sounds like it could rack up read ops quickly for each Index and Union op.
@ptpaterson Currently, we cannot, but it is a valid use case. Thanks for bringing this to our attention. I am tagging this post as a feature request so we can implement this in the future.
Paginate(
Intersection(
Union(
Map(
Var("submissionSet"), // array of id's from client
id => Singleton(Ref(Collection("FormSubmits"), id))
)
),
Match(Index('formSubmits_by_form_and_account'), Var('formId'), Var('accountId'))
)
)
One should be careful using Union this way though, since the cost is basically 2n Read Ops (n = number of Sets in the Union). It may ultimately be cheaper to just read all of the docs and Filter them (it would be in this example).
This is why having a single-read-op function to convert the Ref array to a Set would be huge. But this is cool IMO in any case, so maybe it can find use.
Another contrived example of adding a list of Refs to another index (with possible duplicates):