Rena Hearn
Posts: 0
Joined: Thu Jul 24, 2014 7:04 am

Using $text and $search for string searches

I am trying to search a field called prod_desc.

I can successfully search the first word using the $regex.

I need to search the entire string.
for example "Bimbo Extra Soft White Bread" and I want to search Bread

I have tried return '{"prod_desc":{"$text":{"$search":"'+value+'","$options":"i"}}';
and return '{"prod_desc":{"$text":{"$search":"^'+value+'","$options":"i"}}';

Can someone help me find the right way? No tutorial links please...I came up with these strings after searching the mondodb tutorials. Thanks!!

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Using $text and $search for string searches

Hi Rena,

What is "$text" and "$search" ? Where did you get it from Appery.io documentaion?

Please take a look how to make reg exp search: http://devcenter.appery.io/documentat...

Solution for you:

pre

//To be sure you have correct value.
console.log("value = " + value);

var whereObject = {prod_desc: {"$regex": value, "$options":"gi" } };
return JSON.stringify(whereObject);

/pre

Regards.

Rena Hearn
Posts: 0
Joined: Thu Jul 24, 2014 7:04 am

Using $text and $search for string searches

THAT WORKS!! You are my hero..nearly. Look-up my other topics I posted out of desperation! LOL

Thank You!

ps http://devcenter.appery.io/documentat... this says to see the mongodb documentation for more info.

Return to “Issues”