Ask coding questions

← Back to all posts
How do I find the length of the replit database (js)
Polargaming (0)

Ive tried looking for how to do it but I cant find anything.
Heres the code:

db.list().then(keys =>
{
    console.log(keys.length) //this should work bc db.list() returns an array for me
}
Comments
hotnewtop
ch1ck3n (2393)

your code should work

maybe you havent set any keys to a value?

const Database = require("@replit/database")


const db = new Database()
db.set("key", "value").then(() => {console.log("ok")});



db.list().then(keys => {console.log(keys.length)});

maybe you haven't initialized your database yet.

Polargaming (0)

@ch1ck3n I have initialized the database and added keys