title: How to store a graph that has a cycle in PouchDB?
body: <p>I am making an application in React Native that stores data with PouchDB. I first created a linked list, which is an object of a class named &quot;LinkedList&quot;, which has methods, and stored it in PouchDB. The issue with PouchDB is that it stores data as JSON files, which means that if I tried to recover the linked list in a variable, let's say &quot;myLinkedList&quot;, it would be now of type &quot;Object {}&quot; instead of &quot;LinkedList&quot;.</p>
  <p>Based on an answer from <a href="https://stackoverflow.com/questions/5873624/parse-json-string-into-a-particular-object-prototype-in-javascript">Parse JSON String into a Particular Object Prototype in JavaScript</a>, I managed to solve this using:</p>
  <pre><code> Object.setPrototypeOf(myLinkedList, LinkedList.prototype)
  </code></pre>
  <p>and then myLinkedList would be a &quot;LinkedList&quot; object again.</p>
  <p>But my current problem comes when I make a &quot;DoubleLinkedList&quot; class. As its name suggests, if a node references a next node, then the next one also references the previous one, which is circular. When I try to store an object of that class in PouchDB, as it creates JSON files, when it has to store the reference to the previous node it does not write a pointer but it puts again all the information of the previous node, which will include again the information of the current node because its reference to the next one, and so on. It causes and infinite loop that is making my app to crash. And I suspect that it would crash with any graph that has a cycle.</p>
  <p>How can I solve this problem?</p>