Can using views and update handlers lead to Couch knowing too much about document structure?
I recently floated some ideas with my team along the lines of:
"Hey guys a lot of the stuff we're doing in our .NET layer Couch already supports via views and update handlers".
e.g:
When returning documents: We want to return documents sans the _rev field and "REST"-ify references to other documents or include that document in the response as well.
When inserting documents: We'd like the to be able to supply an object that looks a lot like the one returned to the user when they perform a get.
When updating: we'd like to allow 开发者_高级运维in-place updates (or at least the illusion of them).
All of that seems pretty trivial for Couch views and update handlers; but the biggest argument I got against this was that Couch would then have too much knowledge of the document structure, which would apparently cause maintenance problems and makes it harder to swap out our data access layer.
Are there any best practice guides that say "Yeah this stuff is cool" or "No you never wan't to do that"?
It's true, _show
, _update
, and _list
functions are not very useful for non-human stuff. Basically you put half your logic in CouchDB Javascript and half in the client. You must always keep the server-side Javascript synchronized with clients. You might not be able to run different revisions of the client software with the same server-side code.
There are three exceptions when _show
, _update
, and _list
are useful.
- If the remote client demands a certain data (XML, HTML, etc.),
_show
and_list
are nice. - If you really need to use less bandwidth, the functions can make an application-specific compression protocol. That is, an
_update
function for in-place updates is just a compressed way to say "fetch this document, update one item, then store the new document." - If you have many different client types, with different languages, different versions, different bugs, etc. then you can benefit from making the clients as simple as possible and making the Couch as smart as possible.
精彩评论