For this you can use the $ not operator:
db.test.find( { username: { $not: /substring/ } } );
How in:
> db.test.insert( { username: "Derick Rethans" } );
> db.test.insert( { username: "Hannes Magunusson" } );
> db.test.find( { username: { $not: /ag/ } } );
{ "_id" : ObjectId("511258b36879ad400c26084f"), "username" : "Derick Rethans" }
However, you need to know that regular expressions and uses of the $ not operator do not allow indexes. If you need to make this request very often, you can take a good look at the design of the circuit.
source
share