Short and unique keys in CouchDB

I want to write an abbreviation URL as a standalone CouchApp, but I am wondering if this is possible. Obviously, the basic requirement for shortening URLs is to have short and unique keys.

I want to post the long url of CouchDB and get the shortened url. I was thinking about using an update handler, but it would have to query the DB to check if the key is unique, which seems impossible.

Is there a way to generate short and unique keys with CouchDB? Or do I need a thin wrapper around CouchDB?

+3
source share
1 answer

I would go for thin packaging based on documents with the following structure:

{ _id : short_url , url : long_url }

URL- : _id, PUT _id, . , URL- .

, ", , " - , .

, URL URL-, echo(doc.url,null) _id URL-, . , , URL- , URL- URL-.

+2

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


All Articles