简体   繁体   中英

PouchDB Update Document: DataCloneError

This is the code that I have been working on for a while. For some reason, it is returning me the following error:

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

This is happening even before I tried to use upsert plugin.

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

May I know the resolution for this error?

The Moment instance can't be cloned. Try:

postMessage(moment(0), '*'); // also throws DataCloneError DOMException

The logic for cloning disallows copying functions, which may be the case. Compare with:

postMessage({f: function(){}}); // also throws DataCloneError

And check:

typeof moment(0)._locale.ordinal; // "function"

You'll need to convert the object returned by add() to something that can be cloned, such as a Date, number, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM