Hi i am attmepting to remove anything after the first value e.g.
Collection:{
"_id' :.....
"UrlId" : "5dfc1aa2986b7c30f3398be4",
"coverInput" :
[
"https://test.com/s/files/1/00351576213050",
"https://test.com.au"
],
}
what I want to replace the document with is:
Collection:{
"_id' :.....
"UrlId" : "5dfc1aa2986b7c30f3398be4",
"coverInput" :
[
"https://test.com/s/files/1/00351576213050"
],
}
Im sure this is something simple. I tried this but got an error:
db.test.aggregate([
{
$addFields: {
coverInput: { $substr: [ "$coverInput", 0, { $indexOfBytes: [ "$coverInput", "," ] } ] }
}
}
]).forEach( doc => db.test.updateOne( { _id: doc._id }, { $set: { coverInput: doc.coverInput } } ) )
Thanks in advance!
$substroperator is used to work with strings. You have to use Aggregation array operators to work with array fields.