Extracting a list of substrings from MongoDB using a Regular Expression

后端 未结 3 461
感动是毒
感动是毒 2021-01-15 05:53

I need to extract a part of a string that matches a regex and return it.

I have a set of documents such as:

{\"_id\" :12121, \"fileName\" : \"apple.d         


        
3条回答
  •  盖世英雄少女心
    2021-01-15 06:04

    It's almost undoable to do it in the aggregation pipe, you want to project your matches and include only the part after the period. There is no (yet) operator to locate the position of the period. You need the position because $substr (https://docs.mongodb.com/manual/reference/operator/aggregation/substr/) requires a start position. In addition $regEx is only for matching, you cannot use it in a projection to replace.

    I think for now it's a easier to do it in code. here you could use a replace regex or any other solution provided by your language

提交回复
热议问题