Cloudflare DevelopersCD
Cloudflare Developers7mo ago
3 replies
Hth4nh

Hello everyone,

Hello everyone,

I'm encountering an issue with the Cloudflare Worker KV where I get an empty array when trying to retrieve multiple keys at once.

When I run the following code, it returns an empty array:

const values = await options.env.TEST.get(["2930", "2929"]);
console.log([...values.entries()]); // []

// Expected: [["2930", "foo"],["2929","bar"]]


However, this alternative approach works as expected:

const values = await Promise.all(["2930", "2929"].map((key) => options.env.TEST.get(key)));
console.log(values); // ["foo", "bar"]


According to the documentation, passing an array of keys to the
get()
method should return a
Map
of the key-value pairs.

Here is my
wrangler.jsonc
file for reference:

{
    "$schema": "node_modules/wrangler/config-schema.json",
    "name": "***",
    "main": "./src/index.ts",
    "compatibility_date": "2025-06-20",
    "observability": {
        "enabled": true
    },
    "assets": {
        "directory": "./public/",
        "binding": "ASSETS"
    },
    "kv_namespaces": [
        {
            "binding": "TEST",
            "id": "***",
            "preview_id": "***"
        }
    ]
}


I've also made sure that the
preview_id
is correctly configured for use with
wrangler dev
.

Has anyone else experienced this issue or has any idea what might be going wrong?

Thanks
Was this page helpful?