When uploading data with collections, I have to either pass a key string or use a key gen function:
collections.set('my-collection', (item) => item.key, items)
The keygen works great when the key can be derived from the item value.
But this isn't always the case: sometimes the value we're uploading doesn't have any metadata we can use for the key. Maybe the value is just an array of strings, for example.
The workaround for this right now is to add the key to the value anyway, even if you don't need it. So you're uploading a value like { data: []. key: 'abc' }. Which gets really confusing
And in some cases, even to delete the key in the keygen operator:
collections.set('my-collection', (item) => {
const key = item.key
delete item.key
return key
}, items)
What would be really helpful in these cases is to just pass an array of key/value pairs:
const items = [{ key: 'a', value: { data: {...} }, { key: 'b', value: { data: {...} }]
collections.set('my-collection', items)
This isn't great in docs because we don't really support overloading arguments like this. A setBatch() function might be a cleaner alternative
When uploading data with collections, I have to either pass a key string or use a key gen function:
The keygen works great when the key can be derived from the item value.
But this isn't always the case: sometimes the value we're uploading doesn't have any metadata we can use for the key. Maybe the value is just an array of strings, for example.
The workaround for this right now is to add the key to the value anyway, even if you don't need it. So you're uploading a value like
{ data: []. key: 'abc' }. Which gets really confusingAnd in some cases, even to delete the key in the keygen operator:
What would be really helpful in these cases is to just pass an array of key/value pairs:
This isn't great in docs because we don't really support overloading arguments like this. A
setBatch()function might be a cleaner alternative