CouchDB:在文档中插入新数组

jm81lzqq  于 2022-12-09  发布在  CouchDB
关注(0)|答案(1)|浏览(186)

我有一个由以下材料制成的文档:

{
"_id": "00001.74365CF0449457AA5FB52822DBE1F22A",
"_rev": "1-1b976f3adb75c220aff28b4c69f41e18",
"game": "UT411",
"guid": "74365CF0449457AA5FB52822DBE1F22A",
"sid": "00001",
"playerinfo": [
   {
       "timestamp": "1315503699.777494167",
       "name": "Elisa",
       "ip": "87.66.181.166",
       "gear": "FMAOSTA",
       "weapmodes": "01000110220000020000",
       "isp": "ADSL-GO-PLUS",
       "geoloc": "Hotton:50.266701:5.450000",
       "sid": "00001"
   }
   ]
}

我想要实现的是添加信息到playerinfo数组,以便让我的文档看起来像这样

{
"_id": "00001.74365CF0449457AA5FB52822DBE1F22A",
"_rev": "1-1b976f3adb75c220aff28b4c69f41e18",
"game": "UT411",
"guid": "74365CF0449457AA5FB52822DBE1F22A",
"sid": "00001",
"playerinfo": [
   {
       "timestamp": "1315503699.777494167",
       "name": "Elisa",
       "ip": "87.66.181.166",
       "gear": "FMAOSTA",
       "weapmodes": "01000110220000020000",
       "isp": "ADSL-GO-PLUS",
       "geoloc": "Hotton:50.266701:5.450000",
       "sid": "00001"
   },
   {
       "timestamp": "1315503739.234334167",
       "name": "Elisa-new",
       "ip": "87.66.181.120",
       "gear": "FMAGGGA",
       "weapmodes": "01000110220000020000",
       "isp": "ADSL-GO-PLUS",
       "geoloc": "Hotton:50.266701:5.450000",
       "sid": "00001"
   }
   ]
}

有没有一种方法可以用HTML PUT来实现这一点?
谢谢你!

b1payxdu

b1payxdu1#

简单的答案是获取JSON文档,/example_db/00001.74365CF0449457AA5FB52822DBE1F22A然后修改内容,然后将其放回服务器,放回/example_db/00001.74365CF0449457AA5FB52822DBE1F22A
CouchDB支持一种快捷技术,称为update function。原理是相同的,只是CouchDB将获取文档,进行您实现的任何更改,然后再次存储它-所有这些都在服务器端。
我建议您从前一种更简单的技术开始,接下来,您可以重构以在必要时使用server-side _update函数。

相关问题