Line break \n shows up as \\n in mongoDB document

Hello,

When I try to insert \n into a document, mongo translates it to \n instead which causes issues reading the document data later. I can obviously parse that data with a regex, but is there anyway I can insert the data so that \n would insert as \n instead?

Thanks

Rather than storing long text with line breaks, you could consider storing the text in an array of lines.

To recreate the text with line breaks, you simply loop over. Some use cases might be simpler with an array. For example, you could render your text html friendly by adding the <br> in the looping and terminal friendly by adding the new line instead.

Another advantage, it is easier to view and edit in Compass and shell.

This:

{ _id: 1,
  lines: 
   [ 'Ah ! comme la neige a neigé !',
     'Ma vitre est un jardin de givre.',
     'Ah ! comme la neige a neigé !',
     'Qu’est-ce que le spasme de vivre',
     'À la douleur que j’ai, que j’ai.' ] }

compared to this

{ _id: 0,
  text: 'Ah ! comme la neige a neigé !\\nMa vitre est un jardin de givre.\\n\\nAh ! comme la neige a neigé !\\nQu’est-ce que le spasme de vivre\\nÀ la douleur que j’ai, que j’ai.' }

and in Compass