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

  • SEARCH
  • Home
  • 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 6775597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:55:31+00:00 2026-05-26T15:55:31+00:00

I have a message system where I want different message handlers to be called

  • 0

I have a message system where I want different message handlers to be
called depending on the patterns of the incoming messages.

I have this collection:

[
    { Pattern: "^a", Handler: "Handler1" },
    { Pattern: "^b", Handler: "Handler2" },
    { Pattern: "^c", Handler: "Handler3" }
]

For a given message (a string) I now want to find the first element
where the message matches the pattern and then extract the Handler
name.

That is, for the message “b bla bla bla”, I want to extract
“Handler2”.

Note, I don’t want to use a regex query to find some string in the
database, it is the other way around:
I want to find the element having a pattern which matches a given
string.

My solution right now is to fetch the entire list of patterns and
then iterate and match over all the patterns in my application code
and it works fine, but I am wondering if there is some efficient mongo
query which can be used instead?

  • 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-05-26T15:55:32+00:00Added an answer on May 26, 2026 at 3:55 pm

    You should be fine the way you’re doing it right now if the number of patterns is small.

    If you have a large number of patterns you’ll become a victim of a variation of the Halting problem:
    There no easy way to know if a pattern matches (or not) until you actually execute it with your input string (think of the pattern as a mini-program).

    Or: Given that there is only a finite set of inputs (which is probably not the case), you could store all possible inputs and their corresponding patterns in MongoDB.

    Hope that helps.

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

Sidebar

Related Questions

I have a system that will generate messages sporadically, and I would like to
I have a message handler, which consumes from a JMS queue and that sends
I have a message that I want to fadeIn when a form is successfully
In C++, a console application can have a message handler in its WinMain procedure,
I have a web page that shows different messages according to different conditions. I
Am creating a messaging system model after facebook's messages. The message inbox is threaded,
I have a chatroom system, and I want to use MongoDB as the backend
I'm sure this is a basic OOP question -- I'm designing a message-passing system
I have two different entities of different databases. In my process I want to
I have a web service , i add some extra class which have message

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.