1

Completely new to mongo here.

I have following fields in on of my mysql tables:

id (BIGINT), text (LONGTEXT) #this would contain a long description

I am hoping to change my project from Mysql to MongoDB, but before I do that there is very crucial query that needs to be resolved.

My current query looks for various terms in the description and returns all ids, e.g.

select id from <table> where instr(<table>.text, 'value') or instr(<table>.text, 'value2)

Is it possible for this to be recreated in Mongo? if so how? right now using either the $or or $in seems that I need to have those specific values in some kind of an array in my document.

1 Answer 1

0

MongoDB does not natively support full text search at the moment.

You could use regular expressions but it would be slow (due to not using indexes unless they are rooted).

Query would be like:

db.collection.find({ $or: [{description: /value1/}, {description: /value2/}] })

You could do some preprocessing to insert each word into a searchable array of keywords but if the text is really long you probably don't want to go this route.

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

1 Comment

Thank you for your reply. So this kinda led me down the path of WTF there has to be something... I found a good discussion on stackoverflow.com/questions/5453872/… and I think I am gonna checkout lantern and sphinx.

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.