Question

I may have let a bug loose on our code that essentially ruined some of our db data.

Every now and again we come across a username that has " " in his email so we need to fix this.

How can I search for a value like "/"fubak@drooop.com"/" in one field using my mongo shell?

I have been trying all the combinations I can think of like:

db.users.find(username: /"/" .* /)

and

db.users.find(username: //.*//)

or

db.users.find(username: /"".*/)

But nothing seems to work.

Was it helpful?

Solution

new RegExp('^".*')

This finds all the records that start with ".

Thanks.

OTHER TIPS

Try this:

db.users.find({ email: "(?:[^\\"]+|\\.)*  })   

This will match all documents which contains quotes in the email

Not to sure which one is you problem, so the solutions to both possible scenarios with data in MongoDB like this:

{ "email" : "\"/\"fubak@drooop.com\"/\"" }
{ "email" : "/fubak@drooop.com/" }
{ "email": "\"blablabla@blip.ca\"" }

First document match:

db.problem.find({ email: /^\"/  })

Second document match:

db.problem.find({ email: /^\// })

Third document match

db.problem.find({ email: /^\"/ })

Do not know what you mean otherwise by "having quotes" as that is not valid JSON and by extension is also invalid BSON.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top