'Storing 'Ner' object in Mongodb

I am trying to store a 'js' object in Mongodb collection. This is a 'Ner' object to extract custom entities from a sentence:

  container: Container {
    classes: {},
    factory: {
      logger: [Object],
      fs: [Object],
      arrToObj: [Object],
      normalize: [Object],
      objToArr: [Object],
      stem: [Object],
      removeStopwords: [Object],
      tokenize: [Object],
      timer: [Object],
      storage: [Object],
      'extract-enum': [Object],
      'extract-regex': [Object],
      'extract-trim': [Object],
      'extract-builtin': [Object]
    },
    pipelines: {},
    configurations: {},
    compilers: { default: [DefaultCompiler] },
    cache: { bestKeys: {}, pipelines: [Object] },
    parent: undefined
  },
  settings: {
    container: Container {
      classes: {},
      factory: [Object],
      pipelines: {},
      configurations: {},
      compilers: [Object],
      cache: [Object],
      parent: undefined
    },
    tag: 'ner'
  },
  rules: { en: { hero: [Object] } },
  pipelineProcess: undefined
}

I want to store this in a collection in Mongodb. The problem is, this object cannot be directly stored because it results in a cycle detection error therefore I need to convert it to JSON first, but stringifying it results in {"settings":{"tag":"ner"},"rules":{"en":{"hero":{"name":"hero","type":"enum","rules":[{"option":"spiderman","texts":["spiderman","spider-man","Peter Parker"]}]}}}} which is incomplete and it cannot be parsed back to it's original form. Is there any way to store the object in it's original form in the db to avoid all the issues.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source