如何将HTML插入Mongodb?

Max*_*ges 6 javascript json mongodb

当我尝试粘贴HTML文本文件时,我一直被踢出shell.如何才能做到这一点?我首先需要使用一些javascript来编码它吗?

例:

db.test.insert({x:"<div id='product-description'><p>Who hasn’t wished for a mini-Roomba to    handle the arduous task of cleaning their iPhone screen? Now your dreams have come true!</p>  <p>See the Takara web page for a <a href='http://www.takaratomy.co.jp/products/automee/'  title='automee s' target='_blank'>demo video.</a></p>
<p><strong>Colors: </strong> White, Red, Orange and Blue<br>
Runs on a single AA battery.</p>
<p>1,575 yen</p><!-- end #product-description --></div>"})
Run Code Online (Sandbox Code Playgroud)

编辑

我在我的html中只放了一个引号并用双引号包装整个东西,但仍然没有好处.shell错误:

> j = ({z:"<div id='product-description'><p>Who hasn
---
Unicode text could not be correctly displayed.
Please change your console font to a Unicode font (e.g. Lucida Console).
---

’
bye
Run Code Online (Sandbox Code Playgroud)

rom*_*oll 6

您需要删除或编码字符串中的控制字符.

例如,将文本粘贴到此处,然后编码为UTF-8 ECMAScript(这意味着javascript字符串).

ps:这里有一篇关于javascript中的字符串的文章.告诉你什么需要逃脱.http://docstore.mik.ua/orelly/webprog/jscript/ch03_02.htm