Home:ALL Converter>How to call MongoDB addFields in Spring Mongo?

How to call MongoDB addFields in Spring Mongo?

Ask Time:2020-03-28T03:07:49         Author:vcmkrtchyan

Json Formatter

I have the following type of object in my MongoDB

{
    ...,
    "name": {
        "en": "...",
        "am": "...",
        "ru": "..."
    },
    ...
}

Now I want to run the following query using Spring Data Mongo

db.categories.aggregate({$addFields: {'name': '$name.am'}})

where the am part in $name.am is the locale of the name, hence it must be dynamic. I looked through the MongoTemplate API, and as far as I found, there is no support of addFields operation. Is there any way to achieve this?

Author:vcmkrtchyan,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/60892628/how-to-call-mongodb-addfields-in-spring-mongo
yy