3

For some fields, I uploaded. I want to make sure they didn't get corrupted (not by mongo, but my data generator).

The field of interest would take this regex:

donor_\d{1,2}_\d+

for example:

donor_17_82635294

There is no exception to that rule, so I was wondering if I could use negative look around in regex to find fields that don't meet this rule. The problem with negative look around examples on SO is it seems you have to know what you are looking for, which I don't. I want something like this.

db.collection.find({field:*not*/donor_\d{1,2}_\d+/i})

My other option is just to create a new collection with everything that matches my regex, but this would be much easier.

Thanks J

4

1 回答 1

4

是的,您可以像这样对正则表达式进行否定:

db.collection.find({field: { $not: /donor_\d{1,2}_\d+/i } })
于 2013-08-01T03:39:20.783 回答