Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
Mongoose indexing html text?

I have a doc with field html. The html field stores real html.

schema: {
  html: String
}
doc: {
  "html" : "<p>I am html<p>"
}

And I want to index the html field that when I search "I am html" it should return that doc.

Is there any way to search that document only using text inside of that html tag.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can use $regex operator:

db.collection.find({
  "html": {
    "$regex": "I am HTML"
  }
})

Working example

over 4 years ago · Santiago Trujillo Report

0

If you have text index on this collection, you can search as:

db.collection.find({
  $text: {
    $search: "\"I am html\""
  }
})

With double-quotes wrapped, you can search as exact phrase.

You can also search for exact phrases by wrapping them in double-quotes. If the $search string includes a phrase and individual terms, text search will only match documents that include the phrase.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!