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

172
Views
how do I access a specific field in a compound index using mongo db?

I am using pymongo to query my database to get back results for my API. As of now, I have a compound index to perform string searching:

diseases_collection.create_index([('url', pymongo.TEXT), ('headline', pymongo.TEXT), ('main_text', pymongo.TEXT), ('reports', pymongo.TEXT), ('diseases', pymongo.TEXT), ('syndromes', pymongo.TEXT), 
('event_reports', pymongo.TEXT)])

However, I want a way to search for geographical locations in the reports field only, and not the other fields. How can I do this? Each document has the following structure (obviously different values):

{ 
url: “http://outbreaks.globalincidentmap.com/eventdetail.php?ID=8237”, 
date_of_publication: “2011-02-22 12:29:00”, 
headline: “AUSTRALIA :: Anthrax scare closes Penrith tax office”, 
main_text: “[PenrithStar.com.au]  AUSTRALIA :: Anthrax scare closes Penrith tax office
At about 11.40am, a worker discovered some white powder, believed to have been part of a mail delivery.", 
 reports: [
   {
    diseases: “Anthrax”,
    syndromes: [],
    event_date: “2011-02-22 11:40:00”,
    locations: [“Sydney”, “Penrith”],
    event_reports:[“hospitalised”],
   }
 ] 
}

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

A collection can have at most one text index. When you specify multiple fields to be text indexed, they all are merged into one index.

Therefore you cannot query this index by values of only some of the fields you have indexed.

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!