Pouchdb: Uncaught DataCloneError: Failed to execute 'put' on 'IDBObjectStore': An object could not be cloned.

Created on 6 Apr 2017  路  3Comments  路  Source: pouchdb/pouchdb

Issue

I've got a piece of code to update my data. But I've not been able to do so because I keep getting this one error:

pouchdb.min.js:8 Uncaught DataCloneError: Failed to execute 'put' on 'IDBObjectStore': An object could not be cloned.

I've tried using upsert plugin, regular put with no luck.

When I create data, I do not use put. I use post instead without providing any ID field. Is it because of this?

Info

  • Environment: Electron
  • Platform: Chrome
  • Adapter: IndexedDB
  • Server: None

Reproduce

For creating new document:

db.post({
    "name": document.getElementById('shop_name').value,
    "owner": document.getElementById('owner_name').value,
    "mobile": document.getElementById('mobile_no').value,
    "reg_date": document.getElementById('datepicker').value,
    "exp_date": expiry._d
})

For Updating document:

db.upsert(id, doc => {
  doc.exp_date = moment(date).add(parseInt(document.getElementById('ext_date').value), 'years');
  return doc;
}).then(res => console.log(res)).catch(err => console.log(err));

Most helpful comment

No worries, i've done the same thing a few times!
Cheers!

All 3 comments

I believe this is because you're putting a moment object on the exp_date key in your update function. PouchDB can not serialize those and i was able to repro your error in this JSBin http://jsbin.com/seyukuseku/edit?js,output

Can you try convert it to a timestamp or JSON string, for example with moment().valueOf() ?

Oops. Looks like my mistake. Instead of simply resolving date, I was storing entire moment object. Thanks.

No worries, i've done the same thing a few times!
Cheers!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

daleharvey picture daleharvey  路  4Comments

DiamondYuan picture DiamondYuan  路  4Comments

xub picture xub  路  4Comments

gr2m picture gr2m  路  5Comments

03balogun picture 03balogun  路  4Comments