javascriptdexie

Dexiejs - Filtering returns single value


My dexiedb structure looks like below.

const db = new Dexie('shipment-execution');
db.version(1).stores({
    root: '++id,shipmentid,stopid',
})

My IndexedDB will look like below

| id| shipmentid| stopid|
| 1 | 6000001   | 10    |
| 2 | 6000001   | 20    |
| 3 | 6000001   | 30    |
| 4 | 6000002   | 10    |
| 5 | 6000002   | 20    |

I am trying to get all the data which has shipmentid equal to 6000001. Each time it is returning only one record (the first record ).

db.root.where({shipmentid : '6000001'}).toArray().then((d)=>{
    console.log(d);
})

output is only fetching the first record

| id| shipmentid| stopid|
|  1| 6000001   | 10    |

Please let me know, what I am doing wrong.


Solution

  • (async()=>{
      await db.root.where('shipmentid').equals('6000001').toArray().then((d)=>{
        console.log(d);
      })
    })();
    

    try this and keep in mind shipmentid is string or number