-3

My documents looks like this.

{
   "sId": "s1",
   "source": "September Challenge 1"
},
{
   "sId": "s2",
   "source": "other string multi word"
},
{
   "sId": "s3",
   "source": "September sub string to filter Challenge"
}

I was trying to find the documents only without substring " sub string to filter ". The expected result is:

{
   "sId": "s1",
   "source": "September Challenge 1"
},
{
   "sId": "s2",
   "source": "other string multi word"
},

Which regexp should I use?

I have tried different regexps but haven't achive the expected result. I saw Exclude string from MongoDB regex, but I failed to adapt the answer to my situation.

Sklavit
  • 2,225
  • 23
  • 29

1 Answers1

0

RegExp-only solution is:

db.collection.find({
  source: {
    "$regex": "^(?=.*1)((?! sub string to filter ).)*$"
  }
})

Actually, the question is the same as Regular expression to match a line that doesn't contain a word

Sklavit
  • 2,225
  • 23
  • 29