-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Sub-Document Operations #1559
Comments
Just a heads-up
URI fragments are not send for GET Requests (at least)
netcat and curl to make sure nothing "smart" is interfering, firefox and chrome did send the same |
@st-fankl-in a drat, but thanks! Modified proposal: |
Duplicate of #1280 as well, I'll close that one. |
From the license FAQ on MPL:
Based on this we couldn't pull the JSON Patch functionality in via the source repo, but if it's in hex, for instance, we could handle it that way. Alternately we wake up one morning and @davisp has written his own implementation 😉 |
@janl Hi, not sure if i understood correctly but it seems that you're proposing that |
@lazedo no, I think that's parametrized, you'd still need to know the current rev of the document to make this work. |
@wohali thanks. an alternative for concurrent updates in different parts of document would be to send a computed hash of previous values being updated and have couchdb validate against current values before accepting. that way, two users can have the same |
@lazedo Sorry, that's not under consideration here. This patch proposal will still create a new _rev after it completes, so one of those users will "lose" and either introduce a conflict (if they try and update at the same time) or will receive a 409 and have to retry the operation at the client. Having the server retry multiple times is just asking for runaway race conditions. Remember that previous revisions of the document may no longer exist due to compaction, so it'd be entirely possible for user 1 to transmit their patch (upping the rev from 1 -> 2) and by the time user 2 tries to transmit their patch, referencing rev 1, that revision no longer exists - so the data you want to compare against isn't available. |
Hello! _ Dynamic _rewrites: On the "to" field, the REST API from the browser could be rewritten to target directly the partial document. _ Error handling: What happens if the targeted id/field is missing? There should be a way to handle that (right now, when a document is missing after a rewrite, it's already a mess...). I like your syntax, very comprehensive (but indeed, as said earlier, the '#' could be a technical problem. "/_/" is very interesting, it looks like the old "/#/" but with an underscore, beloved by couchDB). Gilles |
Thanks for your additional input.
unless this works already, there isn’t anything we’re going to change here
missing doc will cause a normal
|
And one more general point. For me, this proposal predates Mango by a couple of years, I only now got around to writing it up. When I talked about this potential feature internally at work, we came to the conclusion that it might be less confusing to use Mango index definitions here, instead of JSON Pointer. The benefit of JSON Pointer fitting natively into URLs are nice, but not necessarily important enough to introduce two different ways for specifying how to specify fields inside a document. As a refresher, here’s how Mango does it:
this would index
So effectively, Mango syntax is just like JSON Pointer, expect every I think this would make for a more coherent proposal. |
I'm not familiar with Mango, can't tell... Here is how I use rewrites (one line extracted from my API, I have a hundred like this):
So, if it can be changed to: |
@linacs > So, if it can be changed to... Have you tried JS rewrites (rewrites as a function) http:https://docs.couchdb.org/en/2.1.2/api/ddoc/rewrites.html?highlight=rewrites#rewrite-section-a-is-stringified-function ? |
OMG, I didn't know about it, my whole architecture was based on CouchDB1.6! (And as I went directly to 2.0, I may have skipped the intermediate changelog) |
Yes.
Indeed. To pattern match req obj parts (path, userCtx and so on) in Erlang-like style you might also find this gist useful https://gist.github.com/ermouth/f954e71411590b66eb58. |
Is there a proposed time frame for something like this to be implemented? I am currently looking at a project where a user may import 1,000,000+ "rows" of data at a time. Not needing to do a full fetch to update would be very, very nice with that amount of data. CouchDB is currently on the same server, no wire, but that may not always be the case. This feature should be a priority, I know my use case would benefit from it, and I assume many others would as well. |
@zekenaulty Sorry, no time frame as of yet. We are a project of volunteers -- pull requests are always welcome! :) |
@zekenaulty in your scenario, you probably don’t want a single doc with 1M+ keys or array elements. |
I believe that your specific use case is better served with e.g. sqlite3 if
I understand it correctly that you are importing kind of .csv data and want
to make partial updates.
…On Fri, 18 Jan 2019 at 11:30, Jan Lehnardt ***@***.***> wrote:
@zekenaulty <https://github.com/zekenaulty> in your scenario, you
probably don’t want a single doc with 1M+ keys or array elements.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1559 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFU80kf1qf1gm87_i41fTn3LBpsPwR_lks5vEaJOgaJpZM4V9xVu>
.
|
Heads-up: proof of concept work on this is progressing on this with a team at work, progress is somewhat slow as we do this as a side and training-project. I just wanted to let the project know in case someone else wants to work on this as well. |
This looks really useful if it could be implemented. Has any thought been given to how you might add/update an item to an array in the documents. Given the original example with a doc with tags, am I right in thinking it might look like this: Add new tag "three"
Update tag "two"
Delete tag "two"
|
(supersedes #1498)
In regular CouchDB operation, clients have to provide a full document revision to be sent in order to make a document update. If only one or a few field values are to be updated, espcially on larger documents, the overhead of sending a full JSON body is significant.
This proposal introduces CouchDB sub-document operations with the help of JSON Pointer (RFC 6901)and JSON Patch (RFC 6902).
JSON Pointer is designed to work inside a URI fragment (think
index.html#foo
), so it’d be great to get single-field oeprations handled that way.Single Field Updates
Sample doc:
Example GET requests
Result:
Result:
Result:
Result:
Result:
Example PUT requests
Result:
New doc revision:
Result:
New doc revision:
Example DELETE requests
New doc revision:
New doc revision:
Multi Field Updates
Of course, making multiple changes will be the next logical step. Thankfull JSON Patch provides a way to do this without having to go too much into canonical JSON serialisation required for a fully fledged diffing algorithm.
New doc revision:
Implementation
Internally, CouchDB will still do the regular load, compare-revision, store procedure, it’s just that the new revision is now produced by applying a JSON Pointer or JSON Patch to the old revision of the doc, instead of being provided by the client.
I’m happy to donate my JSON Pointer implementation, but any other will do, too, this is nice and minimal. For JSON Patch, there is an MPL licensed library which might be problematic for LEGAL/LICENSING reasons, but the implementation doesn’t look too complicated to do from scratch.
Notes
I puntend on
Content-Type
defintions for single field operation because I couldn’t find proper precedent here. Strictly, JSON is always wrapped by an{}
-object value, but we’re allowing to send the native JSON values like strings, numbers, booleans, arrays and objects, and only objects are strictly JSON themselves. I’d love some input here on my sparkling white bikeshed that desparately needs colour suggestions.I opted for keeping only explicit operations on collections, e.g. add value
x
to array in position7
, and not “appendx
to {beginning,end} of array”. While the revision system should avoid any unexpected results here, it felt not quite right to allow relative operations. I might be able to be convinced otherwise :)There is also JSON Merge Patch which is essentially sending fragments of changes that the recipient then has to apply as needed, which would work as well, but might be atiny bit more complicated to implement. If there is significant community interest, we can look into it.
The text was updated successfully, but these errors were encountered: