1

I have an aggregation query. In the $addToFields stage of the query I need to add another field that is a regex of another field. For example, here is an example document:

{
     "host": "axcc91-calpw-11299",
     "site": "gate9",
     "type": "router"
}

I need to apply this regex: ^([^-\d]+) which will produce axcc from the above document. Here is the document i need produced:

{
     "host": "axcc91-calpw-11299",
     "site": "gate9",
     "type": "router",
     "host2": "axcc"
}

How would I apply a regex to either a $project or $addToFields stage to produce the host2 field?

Luke101
  • 59,479
  • 80
  • 216
  • 348

0 Answers0