I have A column like this and it should be split based on the first "-", example is below
MGESAD :
"6095 - NCAM - US - GIUTCB - US Consumer Bank - USRB"
"6595 - NBAM - US - UDAS - Consumer Bank - USRB"
"0595 - NWWAM - US - GWCB - US BANK Bank - USRB - TBL"
I need to split this column into:
Col1 Col2
6095 NCAM - US - GIUTCB - US Consumer Bank - USRB
6595 NBAM - US - UDAS - Consumer Bank - USRB
0595 NWWAM - US - GWCB - US BANK Bank - USRB - TBL
Tried So far:
db.getCollection("arTes").aggregate([
{
$addFields: {
MGE_ID: { $arrayElemAt: [ { "$split": [ "$MGESAD y", "-"] }, 0 ] },
MGE_DESC: { $arrayElemAt:[{ "$split": [ "$MGESAD ", "-"] },2] }
}
}
])
MGE_DESC is giving only 2 element I need entire string excluding the first split.
Let me know if there is any eaiser way to do this?