pouchdb: IDBObjectStore: An object could not be cloned (Ember.js integration)

I just gave a try to 2.2.0. With WebSQL, its working great. But with IndexedDb (Chrome and FF), if i insert a document and query() it, i receive this error:

Uncaught DataCloneError: Failed to execute ‘put’ on ‘IDBObjectStore’: An object could not be cloned. pouchdb.js:2140

I still use the “old” query way, passing along the map function.

It fails on docInfo.data with value:

 Object {value: Object, _id: "5542014-05-05T19:57:35.812Z4E1D619FA-C497-146F-     A636-8BAAEADF6F6F31", _rev: "1-28a58b028db3af911ec118c3aa8cd4a4", _doc_id_rev:      "5542014-05-05T19:57:35.812Z4E1D619FA-C497-146F-A…EADF6F6F31::1-28a58b028db3af911ec118c3aa8cd4a4"}
 _doc_id_rev: "5542014-05-05T19:57:35.812Z4E1D619FA-C497-146F-A636-   8BAAEADF6F6F31::1-28a58b028db3af911ec118c3aa8cd4a4"
 _id: "5542014-05-05T19:57:35.812Z4E1D619FA-C497-146F-A636-8BAAEADF6F6F31"
 _rev: "1-28a58b028db3af911ec118c3aa8cd4a4"
 value: Object
 id: "E1D619FA-C497-146F-A636-8BAAEADF6F6F"
 key: Array[1]
 0: "2014-05-05T19:57:35.812Z"
 ....

Using allDocs({include_docs:true}) works fine.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 37 (26 by maintainers)

Commits related to this issue

Most upvoted comments

I just want to tag something on to this as I’ve been experiencing this same issue. I’ve added date_created fields against my objects using moment.js. If you do myField = moment('DD/MM/YYYY') then make sure you don’t forget the .toString() call at the end otherwise the moment js instance will be passed through and trigger this issue.

@acdcjunior I checked your plunkr. Sorry for not giving you feedback earlier.

The problem is actually not with Angular, and in fact my “fix” doesn’t fix it. The problem is that the object you are trying to save looks like this:

{title: "Rambo", year: 2009, genre: "Action", getTitle: function, _doc_id_rev: "1::2-4627fd86dff4602c56be5ddca8d99a1a"}

You cannot save a PouchDB object with a function on it. You can only save normal objects. If you are ever unsure, you can run:

JSON.parse(JSON.stringify(myObject))

before storing.

Closing this issue. Sorry to take so long to correctly diagnose your problem. 😦

It looks like the root of the issue is with Arrays. Ember is adding a bunch of stuff to the array protototype to make it observable (http://emberjs.com/guides/configuring-ember/disabling-prototype-extensions/). IDB can’t clone those array properly in this case.

Ex: This doc will fail:

_doc_id_rev: "_local/doc_F29A38FD-93D8-F758-B21B-D07D3297BCED::1-      520dd7aef85b72b903e4e34aa69bf239"
 _id: "_local/doc_F29A38FD-93D8-F758-B21B-D07D3297BCED" 
_rev: "1-520dd7aef85b72b903e4e34aa69bf239"
keys: Array[1]

see keys value:

console.dir(docInfo.data.keys)

Array[1] 0: “54F29A38FD-93D8-F758-B21B-D07D3297BCED4F29A38FD-93D8-F758-B21B-D07D3297BCED31” _super: function superFunction(){ addArrayObserver: function (target, opts) { addBeforeObserver: function (key, target, method) { addEnumerableObserver: function (target, opts) { addObject: function (obj) { addObjects: function (objects) { addObserver: function (key, target, method) { any: function (callback, target) { anyBy: function (key, value) { arrayContentDidChange: function (startIdx, removeAmt, addAmt) { arrayContentWillChange: function (startIdx, removeAmt, addAmt) { beginPropertyChanges: function () { cacheFor: function (keyName) { clear: function () { compact: function () { contains: function superWrapper() { copy: function (deep) { decrementProperty: function (keyName, decrement) { endPropertyChanges: function () { enumerableContentDidChange: function (removing, adding) { enumerableContentWillChange: function (removing, adding) { everyBy: function (key, value) { everyProperty: function (key, value) { filterBy: function (key, value) { filterProperty: function (key, value) { find: function (callback, target) { findBy: function (key, value) { findProperty: function (key, value) { frozenCopy: function () { get: function superWrapper() { getEach: function (key) { getProperties: function () { getWithDefault: function (keyName, defaultValue) { hasObserverFor: function (key) { incrementProperty: function (keyName, increment) { insertAt: function (idx, object) { invoke: function (methodName) { isAny: function (key, value) { isEvery: function (key, value) { length: 1 mapBy: function (key) { mapProperty: function (key) { nextObject: function (idx) { notifyPropertyChange: function (keyName) { objectAt: function superWrapper() { objectsAt: function (indexes) { observersForKey: function (keyName) { popObject: function () { propertyDidChange: function (keyName) { propertyWillChange: function (keyName) { pushObject: function (obj) { pushObjects: function (objects) { reject: function (callback, target) { rejectBy: function (key, value) { rejectProperty: function (key, value) { removeArrayObserver: function (target, opts) { removeAt: function (start, len) { removeEnumerableObserver: function (target, opts) { removeObject: function (obj) { removeObjects: function (objects) { removeObserver: function (key, target, method) { replace: function (idx, amt, objects) { reverseObjects: function () { set: function (keyName, value) { setEach: function (key, value) { setObjects: function (objects) { setProperties: function (hash) { shiftObject: function () { someProperty: function (key, value) { sortBy: function () { toArray: function () { toggleProperty: function (keyName) { uniq: function () { unknownProperty: function (key, value) { unshiftObject: function (obj) { unshiftObjects: function (objects) { without: function (value) { proto: Array[0]

When ember is not present:

console.dir(docInfo.data.keys)

Array[1] 0: “554A62460DB-B2B2-A7F9-9061-E06DEAFA11BA4A62460DB-B2B2-A7F9-9061-E06DEAFA11BA31” length: 1 proto: Array[0]

I don’t think there a way to create a “clean” array since Ember alter the original Array.prototype. So… I guess I should disable Ember prototype extension when using Pouchdb.