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?
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));
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!
Most helpful comment
No worries, i've done the same thing a few times!
Cheers!