How to add partial text search functionality in mongodb using nodejs

Issue

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

Solution

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.

Answered By – Shane Scott

Answer Checked By – Mildred Charles (AngularFixing Admin)

Leave a Reply

Your email address will not be published.