CouchDB: insert a new array into a document

I have a document made up 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 to add information to the playerinfo array so that my document looks 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 to do this using html PUT?

thanks!

+6
source share
1 answer

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

CouchDB supports quick access technology called update function. The principle is the same, except that CouchDB will take the document, making all the changes that you implement, and then save it again and again on the server side.

I suggest you start with the first, simpler technique. Then you can reorganize when you need to use the _update function on the server side.

+7
source

Source: https://habr.com/ru/post/896959/


All Articles