pouchdb / upsert

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

Error message not being thrown correctly #17

Closed JoellyR closed 8 years ago

JoellyR commented 8 years ago

Hi just wanted to let you know that I keep getting the following:

{"line":17,"column":41,"sourceURL":"http://192.168.2.4:8100/lib/pouchdb-upsert/dist/pouchdb.upsert.js"}

Instead of the correct error from this line (which is line 17 in pouchdb.upsert.js):

return PouchPromise.reject(new Error('doc id is required'));

My Code for the upsert is:

return patientDb.upsert(doc._id, function (doc) {
          return doc;
        }).then(function (res) {
          // success, res is {rev: '1-xxx', updated: true}
          console.log(JSON.stringify(res));
        }).catch(function (err) {
          console.log(JSON.stringify(err));
        });
      }

Just thought i'd let you know :)

nolanlawson commented 8 years ago

It looks like the reason this is happening is because your doc._id is not defined. It must be defined the first time you pass it in. Hope that helps!