ionic-frameworkpouchdbnosql

AutoIncrement _id in pouchdb


I have implemented a queue in pouchDB, where each record is stored as a separate document. Each record resembles a post request, so that when the user is offline I can save the requests in the queue and later on push it to server as soon as user is online. All the requests must be processed in he same sequence as they are generated. But the problem is there is no sequence of _id in the pouch db. So each time a random id is generated and the sequence is lost. What can I do to get the records in the same sequence as they are saved in the database. I am using pouchDB along with IonicFramework. Thanks.


Solution

  • From @fiatjaf: it is impossible (or not optimal) to have auto-increment _id in PouchDB

    But, you may opt using a timestamp as the _id.

    Example, in your doc object:

    doc = { _id : Date.now(), name: 'Pouch DB', description: 'The best DB' }