Skip to content

Collections: let me pass a single array of key/value pairs to set #1613

@josephjclark

Description

@josephjclark

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions