1

I have a collection Test and data hase stored like this

  {
    "_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"
}

if you see InfoHtml field inside the document it contains html tags i want to remove all html tags

 "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>"

my expectation i should get InfoHTML in every document like this

for example i given

"InfoHTML": "Polling Station No and Name : 11 Abbas Khan Womens College, Darga Compound",

is it possible to remove html tags mongodb.

2 Answers 2

2

From your tags, I am assuming that you are using nodejs. In that case, please check out npm package - striptags.

If I had to do whatever you are trying to do, I will do it like this:

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();
  });
});

Hope it helps!

Sign up to request clarification or add additional context in comments.

Comments

1

No, not in MongoDB.

MongoDB doesn't offer a lot of functionality for processing field values; it is designed to return the field values, and let the client application do further processing; for example as suggested in Ankit's answer.

In the case of string fields, there are a small number of string processing functions available, for example $split, but there is nothing as complex as transforming html to plain text.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.