CouchDB:将新数组插入文档中

发布于 2024-12-03 17:54:49 字数 1387 浏览 1 评论 0原文

我有一个由以下内容组成的文档:

{
"_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来做到这一点?

谢谢!

I have a doc made of:

{
"_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"
   }
   ]
}

what i want to achieve is adding informations to playerinfo array in order to have my doc looking like this

{
"_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"
   }
   ]
}

Is there a way of doing this with HTML PUTs?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白云不回头 2024-12-10 17:54:49

简单的答案是获取 JSON 文档 /example_db/00001.74365CF0449457AA5FB52822DBE1F22A 然后修改内容,然后将其放回服务器,返回/example_db/00001.74365CF0449457AA5FB52822DBE1F22A

CouchDB 支持一种快捷技术,称为更新函数。原理是相同的,只是 CouchDB 会获取文档,进行您实施的任何更改,然后再次存储它——所有这些都在服务器端。

我建议您从前一种更简单的技术开始。接下来,您可以在必要时重构以使用服务器端_update函数。

The simple answer is to fetch the JSON document, /example_db/00001.74365CF0449457AA5FB52822DBE1F22A then modify the contents, then PUT it back to the server, back in /example_db/00001.74365CF0449457AA5FB52822DBE1F22A.

CouchDB supports a shortcut technique, called an update function. The principle is the same, except CouchDB will take the document, make whatever changes you implement, then store it again—all on the server side.

I suggest that you start with the former, simpler technique. Next, you can refactor to use the server-side _update function when necessary.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文