gpt4 book ai didi

node.js - 如何使用 mongodb 命令删除字段内的 html 标签?

转载 作者:太空宇宙 更新时间:2023-11-03 23:02:55 25 4
gpt4 key购买 nike

我有一个集合测试和数据存储如下

  {
"_id": {
"$oid": "58cba49d689493500be8d0a5"
},
"Latitude": 12.96009039,
"Longitude": 77.55213396,
"InfoHTML": "<br/>Polling Station No and Name : 131 43 Ward Office (Revenue),B B M P, 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),B B M P, 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),B B M P, 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();
});
});

希望对你有帮助!

关于node.js - 如何使用 mongodb 命令删除字段内的 html 标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42855951/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com