skip to Main Content

I have to add partial text Search functionality. Can anyone suggest me how to add partial text search functionality in mongodb using nodejs.

2

Answers


  1. You can use $regex for partial text search functionality. Which is what I believe you are looking for.

    MongoDB $regex Docs

    Login or Signup to reply.
  2. Just to clarify, you’re looking for a partial text match in multiple columns?

    If I’m understanding you I believe you could use $or with a $regex for each field in which you’re interested in matching.

    You can use a text match with forward slash. For example if the search term is "mongodb" you could say "$regex": /mongodb/ and it would search a field for that phrase.

    {
        $or: [
            {"field_1": {"$regex": YOUR_SEARCH_STRING} },
            {"field_2": {"$regex": YOUR_SEARCH_STRING} }
        ]
    }
    

    I’m new to Stack Overflow so if this isn’t what you’re looking for let me know and I can try to answer more specifically.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search