mongodb - Not Match Regex for Email -


not sure i'm doing right.

var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-za-z\-0-9]+\.)+[a-za-z]{2,}))$/;  db.test.find({ "email" : { $regex : re}}).count() 

this returns 500 document count expect...but of 1000 documents in collection, there intentionally 500 invalid email addresses. yes, can math, want retrieve bad addresses. how?

db.test.find({ "email" : {$not:{ $regex : re}}}) 

gives me error have expected 500 documents in resulting cursor

error: error: {     "ok" : 0,     "errmsg" : "$not cannot have regex",     "code" : 2,     "codename" : "badvalue" } 

of course, documentation seems support idea $regex not support part of $not. syntax of "re" variable complex.

what have in native mongo / javascript query collection of documents email element not valid email address based on complex regular expression?

fairly new mongo...missing sql server badly...but willing , enthusiastic offer client solution many of great things it's going offer project.

thanks insight (all) might able provide.

mike

your query off , according docs can put regex $not expression.

this return email addresses no match regex.

db.test.find( { email: { $not: re } } )

https://docs.mongodb.com/manual/reference/operator/query/not/


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -