How to store data on browser using NoSQL IndexedDB?

IndexedDB is lrge-sle, NSQL strge system. It lets yu stre just but nything in the users brwser. In dditin t the usul serh, get, nd ut tins, IndexedDB ls surts trnstins.

Hve yu herd f the NSQL dtbse n the brwser?

IndexedDB is lrge-sle, NSQL strge system. It lets yu stre just but nything in the users brwser. In dditin t the usul serh, get, nd ut tins, IndexedDB ls surts trnstins. For example:

NoSQL Database 1.png

Why d we need IndexedDB?


Indexed DB is nsidered mre werful thn llStrge. D yu knw the resn behind it?


n stre muh bigger vlumes f dt thn llStrge

There is n rtiulr limit like in llStrge (between 2.5MB nd 10MB). The mximum limit is bsed n the brwser nd the disk se. Fr exmle, hrme nd hrmium-bsed brwsers llw u t 80% disk se. If yu hve 100GB, Indexed DB n use u t 80GB f se, nd 60GB by single rigin. Firefx llws u t 2GB er rigin while Sfri llws u t 1GB er rigin.


n stre ny kind f vlue bsed n { key: vlue } irs

Higher flexibility t stre different dt tyes. This mens nt nly strings but ls binry dt (rryBuffer bjets, Blb bjets, et.). It uses n bjet stre t hld dt internlly


rvides lku interfes

This is nt vilble in ther brwser strge tins suh s llStrge nd sessinStrge .


Useful fr web litins tht dnt require ersistent internet nnetin

IndexedDB n be very useful fr litins tht wrk bth nline nd ffline. Fr exmle, this n be used fr lient-side strge in rgressive Web s (Ws).


litin stte n be stred

By string the litin stte fr reurring users, the erfrmne f yur litin n be inresed drstilly. Lter n, the litin n syn-u with the bkend server nd udte the litin vi lzy lding.

Lets hve lk t the struture f the IndexedDB whih n stre multile dtbses.


Struture f IndexedDB

IndexedDB 2.png

Hw d we use Indexed DB in ur litins?

In the fllwing setin, well lk t hw t btstr n litin with IndexedDB.


en the dtbse nnetin using windw.indexedDB

windw_indexedDB 3.JPG

In here, UserDB is the dtbse nme nd 1 is the versin f the DB. This wuld return n bjet whih is n instne f the IDBenDBRequest interfe.


rete bjet stre

ne the dtbse nnetin is en, the nugrdeneeded event will be fired, whih n be used t rete bjet stres.

rete bjet stre 4.JPG



Insert dt int the bjet stre

ne nnetin is ened t the dtbse, the dt n be mnged inside the nsuess event hndler. Inserting dt hens in 4 stes.

Insert dt int the bjet stre 5.JPG


ne the insertin funtin is reted, the nsuess event hndler f the request n be used t insert mre rerds.

insert mre rerds 6.JPG


There re mny ertins tht n be erfrmed n the IndexedDB. Sme f them re s fllws:

  • Red/serh dt frm bjet stres by key
  • Red/serh dt frm bjet stres by index
  • Udte dt f rerd
  • Delete rerd
  • Migrte frm revius versin f dtbse, et.

Original post can be found here.

Interested in upgrading your skills? Check out our trainings.

Siddharth Garg
Software Development Engineer

Share the knowledge

Still have questions?
Connect with us
Thank you.
Your request has been received.
Thank you!
The form has been submitted successfully.