Home:ALL Converter>How to use regex in addFields aggregate with mongodb

How to use regex in addFields aggregate with mongodb

Ask Time:2019-09-20T18:27:44         Author:Rakesh

Json Formatter

I want to use regex in addFiels in aggregate with mongodb, but I am not able to do that below is my code which I have tried

$addFields: {slug: {$title: {$regex: '/^[^_s]*$/'}}}

but this is giving mongo error. Please find me solution. My expected output should be slug: "This-is-my-1st-adventure". In my db title: "This is my 1st adventure"

Author:Rakesh,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/58026569/how-to-use-regex-in-addfields-aggregate-with-mongodb
yy