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.

Nertim
  • 380
  • 6
  • 15

1 Answers1

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.

Tyler Brock
  • 29,626
  • 15
  • 79
  • 79
  • 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 http://stackoverflow.com/questions/5453872/full-text-search-in-nosql-databases and I think I am gonna checkout lantern and sphinx. – Nertim Jan 05 '12 at 18:11