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.

有帮助吗?

解决方案

new RegExp('^".*')

This finds all the records that start with ".

Thanks.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top