Only add NEW JSON entries from a URL to a CouchDB using PHP (don't store duplicates) -
server produces json, exposes via url.
my server, b, queries url, grabs json, via php.
i want stick in couchdb, running on b, via php.
the issue way works gives last, say, 200 entries. if query on monday, , 200 entries, , query tuesday , 200 more, it's possible 50 of "new", don't want stick other 150 (that same) in db. what's best way of going this, using php , couchdb/json?
the json entries [that url exposes] have systemid field, increases each element. if query url , receive 200 entries, last element in array should have highest systemid (not confused couchdb _id). can add fields (microtime?) json before stick in couchdb, still need know query in db make sure don't store duplicates.
i think need create view based on these systemids, sort descending, , see of incoming json has systemid greater last element of view, i'm not entirely sure how this.
any appreciated!
edit:
so, let's couchdb has @ moment:
[ { "authorname": "thomson", "createdon": "2013-07-23t22:21:51.822+00:00", "systemid: "101" }, { "authorname": "johnson", "createdon": "2013-07-23t22:22:51.822+00:00", "systemid: "102" } ]
how run query on couchdb "102"? once have that, know how handle rest. thanks!
so, sorted out. here's how it:
first, created view, this:
function(doc) { if (doc.burnedid) { emit(doc.burnedid); } }
then, php script queries url this:
http://myserver.com/mydb/_design/systemid/_view/get%20systemid?descending=true&limit=1
which returns json document that, eventually, contains key of highest systemid in couchdb.
i can use check against incoming json, , add newer entries database.
note, work if [incoming] json didn't have systemid. use microtime(true) php function generate timestamp (really, increasing large floating point number) , add json before put in database. use in same fashion.
hope helps someone!
Comments
Post a Comment