0

I'm creating an offline app using PouchDB. Right now I'm loading the db and posting a couple of rows, but this means that the rows are getting duplicated each time I load. Is there a standard pattern for initialising and pre-populating a db? What if I want to update the increase the amount of data pre-populated in the future?

Dan
  • 3,229
  • 2
  • 21
  • 34

1 Answers1

0

The best way I can think of is getting the total_rows to make sure if it hit your limit, and if not, Post more items to it, otherwise, do whatever you need to do. This ensures that you don't get duplicated data.

DB.allDocs({include_docs:true}, function(error, response) { 
  if(response.total_rows != YOURMAXLIMIT) {
      // Add more items
  }
});
Rijvi Rajib
  • 1,080
  • 2
  • 11
  • 27