How can I write the below MongoDB operation into Java Springboot code?
db.collection.aggregate({
"$group": {
_id: {
$trim: {
input: "$name"
}
},
doc: {
"$first": "$$ROOT",
}
}
},
{
"$replaceRoot": {
"newRoot": "$doc"
}
})
Hope you are using mongo template. You can use the BSON approach. TRICK TO CONVERT MONGO SHELL QUERY
But you can also try this. Please make sure this is working