incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexander Shorin <kxe...@gmail.com>
Subject Re: compare two documents and update
Date Sat, 01 Mar 2014 18:04:41 GMT
Hi,

This could be done pretty easily with Python:

import json
import couchdb    # https://pypi.python.org/pypi/CouchDB
import jsonpatch  # https://pypi.python.org/pypi/jsonpatch

server = couchdb.Server()
db = server['mydb']
# existed doc
doc_a = db['some-doc-id']
# another document not in the database
doc_b = json.load(open('doc.json', 'rb'))
# compare docs producing difference as json patch
patch = jsonopatch.make_patch(doc_a, doc_b)
# update existed doc by this difference
patch.apply(doc_a)
# upload it to he database
db.save(doc_a)

--
,,,^..^,,,


On Sat, Mar 1, 2014 at 9:54 PM, Asoh Frank <asoh2004@yahoo.com> wrote:
> Greetings,
>
> I am new to non relational databases and couchdb as a whole. I want to ask if there is
any flexible possibility of comparing an existing document in the couchdb database with another
document(json file) not in the database then the difference between them will be uploaded(updated)
to the current existing document ?
>
> Best regards.

Mime
View raw message