Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7744001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:40:14+00:00 2026-06-01T09:40:14+00:00

I am creating an autocomplete service against my mongo db posts collection where a

  • 0

I am creating an autocomplete service against my mongo db posts collection where a user can start to type the title of a post. It should return all posts with that keyword in the title and sort by a field called ‘total’.

I have a field called “lower” that is a lowercase version of the title field we want to search, and that has an index set on it. Since I am looking for any keyword match, I am doing a regex search against lowerCaseTitle for words that appear anywhere in the title, not just in the beginning.

I looked at the execution plan and it looks like does a scan through every item (the full posts collection has 10061 items). I tried hinting at both the “lower_1” index and the “total_-1” index and they seem similar, but the total index seems better with a lower nscanned number if I set a limit number of 50 to the query. Is there anything I can do to optimize? I can’t think of anything simple off the top of the head for this kind of full-text searching.

"cursor" : "BtreeCursor lower_1",
    "nscanned" : 10061,
    "nscannedObjects" : 2,
    "n" : 2,
    "scanAndOrder" : true,
    "millis" : 154,
    "nYields" : 0,
    "nChunkSkips" : 0,
    "isMultiKey" : false,
    "indexOnly" : false,
    "indexBounds" : {
        "lower" : [
            [
                "",
                {

                }
            ]
        ]
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:40:15+00:00Added an answer on June 1, 2026 at 9:40 am

    I am doing a regex search against lowerCaseTitle for words that appear anywhere in the title, not just in the beginning.

    From the documentation:

    For simple prefix queries (also called rooted regexps) like /^prefix/, the database will use an index when available and appropriate (much like most SQL databases that use indexes for a LIKE 'prefix%' expression). This only works if you don’t have i (case-insensitivity) in the flags.

    In other words, no, MongoDB does not support searching substrings in a fast manner.

    However, you can do the following to support words starting with a given string:

    BlogPost { 
      Title : "This is furiously interesting post"
      TitleSearch : [ "this", "is", "furiously", "interesting", "post" ]
    }
    

    Now, with TitleSearch indexed and using a rooted regex, a search for 'inter' would return the sample, also for 'furious', but not for 'eresting'.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a user control in ASP.NET (using VB) that uses the autocomplete
First off, forgive my English, my attempt, I am creating a autocomplete user control,
I am creating a autocomplete textbox for a application for touch screen device jquery
Creating liquid layouts is an immense pain. Now, I totally understand that tables should
Creating a google map with store locations within 50 miles of user entered address.
When creating a new service in a WCF service project, Visual Studio will automatically
I'm using the AutoComplete UI widget for a form to allow users to type
See the screenshot here: I'd like the user to just type a city or
I'm creating an autocomplete from a page that returnes values as a text list,
My actual question is how would I go about creating a autocomplete dropdown off

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.