Skip to content
← Back to Community
How do I find the length of the replit database (js)
Profile icon
Polargaming

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 }
Voters
Profile icon
Polargaming
Comments
hotnewtop
Profile icon
ch1ck3n

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.

Profile icon
Polargaming

@ch1ck3n I have initialized the database and added keys