pouchdb / upsert

PouchDB plugin for upsert() and putIfNotExists() functions
Apache License 2.0
149 stars 25 forks source link

upsert bulk function #57

Open etcware opened 6 years ago

etcware commented 6 years ago

I have a problem similar to https://stackoverflow.com/questions/44357946/update-more-than-one-document-in-a-loop and I tried to solve it as described in the last answer. But it doesn't work, because when the upsert diffFunc enter the external loop is ended and v1...v6 are valued by the last loop iteration. Is it possible to get the id value inside the upsert diffFunc? Do you can suggest any other solution? The last comment in the post is mine (Alessandra).

dperetti commented 6 years ago

Just faced this issue and did this:

Promise.all(notes.map(note => db.upsert(note.docId, doc => {
      doc.syncCursorId = syncCursorId
      return doc
})).then(results => console.log(results))