Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

262
Vistas
IndexedDB - cursor applying filter doesn't return anything

I have a problem with filtering using indexedDB.

I have users with name aaa, bbb, ccc and index is on name.

Here's my code and no matter which IDBKeyRange filter I apply on cursor, I get empty list. I tried with bound and lowerBound.

     const usersData = [
        { id: '1', name: 'bbb', email: 'bbb@somewhere.com' },
        { id: '2', name: 'aaa', email: 'aaa@somewhere.com' },
        { id: '3', name: 'ccc', email: 'ccc@somewhere.com' },
     ];
     let db;
     let request = window.indexedDB.open('test1', 1);
     
     request.onerror = function(e) {
        console.error(e);
     };         
     request.onsuccess = function(e) {
        db = e.target.result;
        console.log('success, db: ', db);            
     };
     
     request.onupgradeneeded = function(e) {
        db = e.target.result;
        let objectStore = db.createObjectStore('user', { keyPath: 'id' });            
        for (let user of usersData) {
           objectStore.add(user);
        }
        objectStore.createIndex('name', 'name');         
     }
             
     function readAll() {
        let objectStore = db.transaction(['user'])
        .objectStore('user');

        let range = null;
        //range = IDBKeyRange.lowerBound('aaa', true);  // ? doesn't working
        range = IDBKeyRange.bound(['aaa'], ['ccc'], true, true);

        objectStore.openCursor(range).onsuccess = function(e) {
           let cursor = e.target.result;               
           if (cursor) {
              console.log(cursor.key, cursor.value);
              cursor.continue();
           } 
           else {
              console.log('---------------------------------');
           }
        };
     }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Change the code so that you open the cursor on the index, not the object store.

// ...
let index = objectStore.index('name');
// ...
index.openCursor(range).onsuccess = // ...
// ...
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda