如何将HTML插入Mongodb? [英] How do I insert HTML into Mongodb?
问题描述
当我尝试粘贴HTML文本文件时,我一直被踢出shell。如何才能做到这一点?我是否首先需要使用一些javascript对其进行编码?
I keep getting kicked out of the shell when I try to paste in an HTML text file. How can this be done? Do I first need to use some javascript to encode it or something?
示例:
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>"})
编辑
我在html中只放了一个引号并用双引号包装整个东西,但仍然没有好处。 shell错误:
I put only single quotes inside my html and wrapped the whole thing in double-quotes, but still no good. shell error:
> 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
推荐答案
您需要删除或编码字符串中的控制字符。
You need to remove or encode the control characters in your string.
例如,将文本粘贴到此处,然后编码为UTF-8 ECMAScript(表示javascript字符串) )。
For example, paste your text in here, and encode to UTF-8 ECMAScript (which means javascript strings).
ps:这里有一篇关于javascript中字符串的文章。告诉你需要逃避什么。 http://docstore.mik.ua/orelly/webprog/jscript/ch03_02.htm
ps: here an article about strings in javascript. tells you what needs escaping. http://docstore.mik.ua/orelly/webprog/jscript/ch03_02.htm
这篇关于如何将HTML插入Mongodb?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!