javascript - Escape backslash and double quote in mongo $text -


i have problem mongo $text $search phrase. want create $search phrase variable. $search phrase should this: "\"search\"". in javascript can escape quote , backslash adding 1 more slash: '\\\"search\\\"'. if print or pass somewhere different results in different environments. in browser '\"search\"' in node js (5.x) '\\"search\\". matter? final goal built $search string using in mongodb $text operator. maybe can me or question above.

(i know it's late, want answer in case find page looking way solve problem)

you don't have write right javascript format. leave in mongoshell

db.collection.find({$text:{$search:'\"search\"'}}, function... 

so, way approach generic string is

var search = "generic phrase search"; search = '\"' + search.split(' ').join('\" \"') + '\"'; db.collection.find({$text:{$search:search}}, function... 

hope it's helpful.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -