My mongo documents all contain a field called templateName
. There are a few documents that contain the value: a_SystemDefaultTemplate
, b_SystemDefaultTemplate
, c_SystemDefaultTemplate
etc.
I would like to find
those documents whose templateName does not end with (or contain) SystemDefaultTemplate
I know it can be done using the $not
operator like so:
db.collection.find({templateName: {$not: /.*SystemDefaultTemplate$/}})
But how do I do the same using regex?
I have tried the below but it does not seem to work.
db.collection.find({templateName: {$regex: "^(.*SystemDefaultTemplate$)"}})
$not
and$regex
...{$not: {$regex: "^(.*SystemDefaultTemplate$)"}}
– Pentup