CouchDB:将新数组插入文档中
我有一个由以下内容组成的文档:
{
"_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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简单的答案是获取 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.