1

1) I have a string with about 30 comma seperated elements. Like str1, str2, str3 etc. "INPUT_STRING"

2) I have mongo db collection "allowed_strings". For instance, str1, str2, str3 etc. There are 1500 strings and in future would be max 2000. ALLOWED_STRING collection.

3) I need to take IN_STRING and match ALLOWED_STRING. As a result create new json array (or comma seperated string) "MATCHED".

4) In reality it is a bit more complex as str1, str2 etc. often comes in different forms like str-1 instead of str1. Or there could be also synonyms of str1 (for instance, syn1) that are stored in "allowed_strings.synonyms" collection.

I never worked with mongodb and node js. And here I have two solutions in mind:

  • First: there are not so many elements in total (only 2000 elements in collection ALLOWED_STRING and about 30 elements in comma separated string INPUT_STRING); I can read all collection into node js memory at once and then do search using node js (including custom search by synonyms etc.)

OR

  • SECOND: I can loop through comma separated strings "IN_STRING" taking elements one by one (str1, then str2 etc.) and each time perform mongo db query

Which is better?

2
  • If amount of strings is fixed and cannot rapidly grow overtime, I would prefer first option as you need custom pattern to match anyway.. Commented Jan 1, 2018 at 15:49
  • Do you have an idea of how you are modeling your documents? Commented Jan 1, 2018 at 17:10

1 Answer 1

1

If the amount of information is not going to grow a lot, and every search is going to involve iterative searches, in my opinion best option would be doing it in Node.js.

But, if you achieve to do only one search in Mongo with a regex probably this would be more efficient. But you will have to work hard creating that regex condition dynamically.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.