如何使用mongodb命令删除域内的HTML tage?
我有一个收集testing和数据hase像这样存储
{ "_id": { "$oid": "58cba49d689493500be8d0a5" }, "Latitude": 12.96009039, "Longitude": 77.55213396, "InfoHTML": "<br/>Polling Station No and Name : 131 43 Ward Office (Revenue),BBMP, Room No-01 <br/><br/><a href='http://psleci.nic.in/pslinfoc.aspx?S=S10&A=168&P=131 ' target='_blank'><b>Click here for information<b><\/a>", "state": "karnataka", "district": "bbmpcentral", "constituency": "chamrajpet" }, { "_id": { "$oid": "58cba645734d1d2ca8573b20" }, "Latitude": 12.96001673, "Longitude": 77.55207344, "InfoHTML": "<br/>Polling Station No and Name : 132 43 Ward Office (Revenue),BBMP, Room No-02 <br/><br/><a href='http://psleci.nic.in/pslinfoc.aspx?S=S10&A=168&P=132 ' target='_blank'><b>Click here for information<b><\/a>", "state": "karnataka", "district": "bbmpcentral", "constituency": "chamrajpet" }, { "_id": { "$oid": "58cbaa4d734d1d2ca8573c9b" }, "Latitude": 12.96519429, "Longitude": 77.58097308, "InfoHTML": "<br/>Polling Station No and Name : 11 Abbas Khan Womens College, Darga Compound, <br/><br/><a href='http://psleci.nic.in/pslinfoc.aspx?S=S10&A=169&P=11 ' target='_blank'><b>Click here for information<b><\/a>", "state": "karnataka", "district": "bbmpcentral", "constituency": "chickpet" }
如果您在文档中看到InfoHtml字段,那么它包含html标记,我想要删除所有的html标记
"InfoHTML": "<br/>Polling Station No and Name : 131 43 Ward Office (Revenue),BBMP, Room No-01 <br/><br/><a href='http://psleci.nic.in/pslinfoc.aspx?S=S10&A=168&P=131 ' target='_blank'><b>Click here for information<b><\/a>"
我的期望,我应该得到这样的每个文档的InfoHTML
例如我给
"InfoHTML": "Polling Station No and Name : 11 Abbas Khan Womens College, Darga Compound",
是否有可能删除html标签mongodb。
从你的标签,我假设你正在使用nodejs。 在这种情况下,请查看npm软件包 – striptags 。
如果我不得不做任何你想做的事,我会这样做:
var striptags = require('striptags'); var YourCollectionName = require('path-to-your-model'); YourCollectionName.find({}, function (err, docs) { if (err) { //handle or throw error } // For all the documents, remove html tags and save docs.forEach(function(doc){ doc.InfoHTML = striptags(doc.InfoHTML); doc.save(); }); });
希望能帮助到你!
不,不在MongoDB中。
MongoDB不提供很多处理字段值的function; 它旨在返回字段值,并让客户端应用程序做进一步的处理; 例如Ankit的答案中所build议的 。
在string字段的情况下,可以使用less量的string处理函数 ,例如$ split,但没有像将html转换为纯文本那么复杂。
- 通过多个页面保持socket.io中的variables
- 为什么mongoose.connect()在没有作为mongoose对象的方法时工作得很好?
- Express js post方法错误地读取编码的数据
- 如何在将图像上传到服务器时传递多个值(使用AngularJS和NodeJS进行file upload)?
- 在node.js和express中处理exception
- 用json发送html文件并让浏览器重新加载该json而不用重新加载页面
- 如果我正在通过Oauth构build应用程序进行身份validation,那么使用Cookie进行会话有意义吗?
- angular色http发布数据对象不被节点服务器视为对象
- 护照authentication失败导致redirect循环