Mike T
Mike T

Reputation: 415

mongoexport with regex query

I am trying to export from a mongo database using the following mongoexport command to search out text emoticons :

mongoexport -d <db> -c <col> -f text -q '{text: /.*:\)/}'

But when I try to execute the command mongoexport returns:

assertion: 10340 Failure parsing JSON string near: text: /.*:

I have tried to use the hex escape for the right paren:

mongoexport -d <db> -c <col> -f text -q '{text: /.*:\x29/}'

but I get the same error at the same location. It appears the mongoexport parser halts when it encounters '\'. I have a difficulty believing that mongoexport has this limitation (since it makes using regular expressions nearly impossible), so what am I doing wrong?

Upvotes: 4

Views: 3875

Answers (1)

shelman
shelman

Reputation: 2699

Can I ask why you are trying to escape the right paren? I tried your query without the escape before the right paren and it worked : '{text: /.*:)/}'

As an alternative, if you need the escape in the query then you have to escape the escape symbol, since the string is getting parsed twice (the shell, then the database) : '{text: /.*:\\)/}'

Upvotes: 2

Related Questions