首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用mongodb从html文档中删除html标记

问如何使用mongodb从html文档中删除html标记
EN

Stack Overflow用户
提问于 2016-08-02 18:33:42
回答 1查看 533关注 0票数 1

我使用的是mongodb版本3.2.4。我有一个只有一个字段的集合,Html (除了id,ofc)。总共有8.821.851份文件。每个文档代表大约5页纯文本的html文件,但是大约20页带有html标签。

当我尝试搜索包含某些文本的文档(例如,ID号是"5555888“或名称是"John")的简单查询时,它不会返回任何结果,或者我必须等待很长时间。

我想从所有文件中删除html标签,以减小所有文件的大小。那么查询特定文档的速度会更快。

对于这个任务,Mongodb有解决方案吗?

一个html文档的示例(小部分):

代码语言:javascript
复制
"<a name=\"JR_PAGE_ANCHOR_0_1\"></a>\n<table style=\"width: 595px; border-collapse: collapse; empty-cells: show\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" bgcolor=\"white\">\n<tr>\n  <td style=\"width: 20px; height: 1px;\"></td>\n  <td style=\"width: 40px; height: 1px;\"></td>\n  <td style=\"width: 20px; height: 1px;\"></td>\n  <td style=\"width: 22px; height: 1px;\"></td>\n  <td style=\"width: 108px; height: 1px;\"></td>\n  <td style=\"width: 88px; height: 1px;\"></td>\n  <td style=\"width: 117px; height: 1px;\"></td>\n  <td style=\"width: 80px; height: 1px;\"></td>\n  <td style=\"width: 79px; height: 1px;\"></td>\n  <td style=\"width: 1px; height: 1px;\"></td>\n  <td style=\"width: 20px; height: 1px;\"></td>\n</tr>\n<tr valign=\"top\">\n  <td colspan=\"11\" style=\"width: 595px; height: 20px;\"></td>\n</tr>\n<tr valign=\"top\">\n  <td colspan=\"2\" style=\"width: 60px; height: 46px;\"></td>\n  <td colspan=\"2\"><img src=\"/servlets/PublicReportServlet?_image_=img_0_0_9\" style=\"height: 46px\" alt=\"\"/></td>\n  <td colspan=\"6\" style=\"text-align: right;\"><span style=\"font-family: Times New Roman; color: #000000; font-size: 18.0px; font-weight: bold;\">NESLUŽBENA KOPIJA</span></td>\n  <td style=\"width: 20px; height: 46px;\"></td>\n</tr>\n<tr valign=\"top\">\n  <td style=\"width: 20px; height: 12px;\"></td>\n  <td colspan=\"9\"><span style=\"font-family: Times New Roman; color: #000000; font-size: 10.0px; font-weight: bold;\">REPUBLIKA HRVATSKA</span></td>\n  <td style=\"width: 20px; height: 12px;\"></td>\n</tr>\n<tr valign=\"top\">\n  <td colspan=\"11\" style=\"width: 595px; height: 4px;\"></td>\n</tr>\n<tr valign=\"top\">\n  <td style=\"width: 20px; height: 12px;\"></td>\n  <td colspan=\"9\"><span style=\"font-family: Times New Roman; color: #000000; font-size: 10.0px; font-weight: bold;\">Općinski sud u Novom Zagrebu</span></td>\n  <td style=\"width: 20px; height: 12px;\"></td>\n</tr>\n<tr valign=\"top\">\n  <td style=\"width: 20px; height: 12px;\"></td>\n  <td colspan=\"9\"><span style=\"font-family: Times New Roman; color: #000000; font-size: 10.0px; font-weight: bold;\">ZEMLJIŠNOKNJIŽNI ODJEL NOVI ZAGREB</span></td>\n  <td style=\"width: 20px; height: 12px;\"></td>\n</tr>\n<tr valign=\"top\">\n  <td style=\"width: 20px; height: 12px;\"></td>\n  <td colspan=\"4\" style=\"border-bottom-style: solid; border-bottom-width: 1px; border-bottom-color: #000000; \"><span style=\"font-family: Times New Roman; color: #000000; font-size: 10.0px; font-weight: bold;\">Stanje na dan: 19.06.2016 23:05</span></td>\n  <td colspan=\"5\" style=\"border-bottom-style: solid; border-bottom-width: 1px; border-bottom-color: #000000; text-align: right;\"><span style=\"font-family: Times New Roman; color: #000000; font-size: 10.0px;\">Verificirani poduložak</span></td>\n  <td style=\"width: 20px; height: 12px;\"></td>\n</tr>\n<tr valign=\"top\">\n  <td style=\"width: 20px; height: 12px;\"></td>\n  <td colspan=\"9\"></td>\n  <td style=\"width: 20px; height: 12px;\"></td>\n</tr>\n<tr valign=\"top\">\n  <td style=\"width: 20px; height: 12px;\"></td>\n  <td colspan=\"5\"><span style=\"font-family: Times New Roman; color: #000000; font-size: 10.0px; font-weight: bold;\">Knjiga PU: ZAPRUDSKI OTOK 
EN

回答 1

Stack Overflow用户

发布于 2016-08-02 18:50:58

显然,您在MongoDB中有一个巨大的集合,您想要编辑该集合上的每个文档。文档编辑或多或少是字符串编辑和处理。

这不是MongoDB的任务。您应该使用一些MongoDB客户端或驱动程序,并编写一个非常简单的代码(可能使用c#或java )来遍历每个文档并对其进行编辑,

如果您在编写代码时需要帮助,我可以提供一个小的JAVA示例,它可以提供帮助。如果你需要,只需评论即可。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38718043

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档