Searching string with special characters in MongoDB document

后端 未结 7 1891
清歌不尽
清歌不尽 2020-12-05 23:57

I want to search values having special characters such as \" $ / . @ > \" in a document.

Lets consider, I\'ve myKey with values like \"test$aus

相关标签:
7条回答
  • 2020-12-06 00:40

    You can use this:

    db.myCollection.find({myKey:{ $regex:new RegExp('^' + 'test$australia'.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') + '$', 'i')}})
    
    0 讨论(0)
提交回复
热议问题