我有以下mongodb文档结构:
[
{
"_id": "04",
"name": "test service 4",
"id": "04",
"version": "0.0.1",
"title": "testing",
"description": "test",
"protocol": "test",
"operations": [
{
"_id": "99",
"oName": "test op 52222222222",
"sid": "04",
"name": "test op 52222222222",
"oid": "99",
"description": "testing",
"returntype": "test",
"parameters": [
{
"oName": "Param1",
"name": "Param1",
"pid": "011",
"type": "582",
"description": "testing",
"value": ""
},
{
"oName": "Param2",
"name": "Param2",
"pid": "012",
"type": "58222",
"description": "testing",
"value": ""
}
]
}
]
}
]
Run Code Online (Sandbox Code Playgroud)
我已经能够使用$ elemMatch来更新操作中的字段,但是当我尝试对参数执行相同的操作(修改)时,它似乎不起作用.我想知道我应该尝试哪种其他方法,以便能够成功更新特定参数中的字段,通过其pid查找它.
我目前拥有且不起作用的更新代码如下所示:
var oid …Run Code Online (Sandbox Code Playgroud) 我目前正在迭代类似于此的值:
Administer PoolA servers :id=server@Pool@5@example.com
Run Code Online (Sandbox Code Playgroud)
并想用“\”替换空格以使其看起来像这样(或在每个空格之前添加\):
Administer\ PoolA\ servers\ :id=server@Pool@5@example.com
Run Code Online (Sandbox Code Playgroud)
我知道正则表达式会帮助我做到这一点,但没有成功,任何帮助将不胜感激。