Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

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

Open
vedtam opened this issue Dec 7, 2016 · 1 comment
Open

Comments

@vedtam
Copy link

vedtam commented Dec 7, 2016

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.

@nrjgbg
Copy link

nrjgbg commented Mar 10, 2017

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants