DEV Community

Cover image for WRONGTYPE Operation against a key holding the wrong kind of value
Manuel Alférez Ruiz
Manuel Alférez Ruiz

Posted on

WRONGTYPE Operation against a key holding the wrong kind of value

The error arises when attempting a KV operation (set or get) in Vercel after creating an entry using a different data structure.

Replicating the error

await kv.set('userSession', '123abc');
Enter fullscreen mode Exit fullscreen mode

Subsequently, we opt to change the data structure.

await kv.hset('userSession', { userId: 123, email: 'ex@example.com' });
Enter fullscreen mode Exit fullscreen mode

Error:

UpstashError: WRONGTYPE Operation against a key holding the wrong kind of value, command was: ["hset","userSession", ...]
Enter fullscreen mode Exit fullscreen mode

Solution

Remove the key from Vercel before modifying the data structure.

  1. Go to Vercel: https://vercel.com/dashboard/stores/kv
  2. Delete that key:
DEL userSession
Enter fullscreen mode Exit fullscreen mode

Image description

Top comments (0)