app-pouchdb icon indicating copy to clipboard operation
app-pouchdb copied to clipboard

How to create multiple documents using a single app-puchdb element?

Open vedtam opened this issue 8 years ago • 1 comments

I am trying to save a list of products to the local database, coming from my server in the form of a json array using the app-pouchdb element.

What I need is to create a document for each product so I can query the local database later, using the document _id, but as I see the element asks for a doc-id (ie.: parsip) right at the start:

<app-pouchdb-document
    db-name="cats"
    doc-id="parsnip"
    data="{{cat}}">
</app-pouchdb-document>

Using the same _id, rows are overwritten and I end up with only one document in the end. I have read the docs a few times, but I can't find any hint on achieving separate document for each product from my array.

vedtam avatar Dec 07 '16 21:12 vedtam

After some testing around I came to the conclusion that this works but is somewhat undocumented.

Just set an id to the document.

      <app-pouchdb-document
        id = "timeDoc"
        db-name="ezq"
        data="{{time}}">
      </app-pouchdb-document>

Remember to omit the doc-id since we want a new one made.

Then in a button event just call save on the document like this.

      _addTime: function(){
        this.$.timeDoc.save();        
      }

That's all there is to it.

nrjgbg avatar Mar 10 '17 10:03 nrjgbg