我正在try 对嵌套文档中字段的值进行$修剪,但我一直无法弄清楚如何使其工作.
我想在所有文档的code
字段上运行$trim,以便从MongoDB中静止的文档中删除前导空格和尾随空格.
我正在使用MongoDB 4.2.
我的文档 struct 如下:
{
"_id": "root_id",
"products": [
{
"id": "p1",
"code": "TRAILING "
},
{
"id": "p2",
"code": " LEADING"
}
{
"id": "p3",
"code": "CLEAN"
}
]
}