Patching a non-existing document

35 views
Skip to first unread message

Jahmai Lay

unread,
May 23, 2013, 11:27:55 PM5/23/13
to rav...@googlegroups.com

I use session.Advanced.Defer(...) to patch a document (e.g. set a property value).
After I call SaveChangesAsync() if the document is present, the change works.
If the document is missing, it does not throw an error and (obviously) no document is modified.

It would be better to not have to precede the patch with a call to Load just to see if the document exists before patching.

Perhaps the better behavior is to throw 401 back to the client when trying to patch a document that does not exist?

Kijana Woodard

unread,
May 23, 2013, 11:31:00 PM5/23/13
to rav...@googlegroups.com

I'd love something like concurrent dictionary's AddOrUpdate for this.

--
You received this message because you are subscribed to the Google Groups "ravendb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jahmai Lay

unread,
May 23, 2013, 11:33:11 PM5/23/13
to rav...@googlegroups.com

That feature would be good, too.

Oren Eini (Ayende Rahien)

unread,
May 24, 2013, 1:38:08 AM5/24/13
to ravendb
A pull request for either option would be great

Jahmai Lay

unread,
May 25, 2013, 11:30:07 AM5/25/13
to rav...@googlegroups.com

Ok, according to the server code, HTTP method "PATCH" goes through a logic path that will return 404 for missing docs.

However - currently both IDatabaseCommands.Patch and IAsyncDocumentSession.Defer both use use Batch() that goes through as a "POST".

Now my guess is that when you do Batch commands its hard to tell exactly what the response should be - if you patch many docs and one is missing etc.
Also, changing this to throw on a missing doc might break some deployments (?)

At this point I don't know what Raven should be doing, but here's what I think;

- IDatabaseCommands.Patch should use the "PATCH" method instead of forwarding to Batch() / "POST".
- Add PatchAsync to IAsyncDatabaseCommands and behave the same as IDatabaseCommands.Patch
- IAsyncDocumentSession.Defer should keep using Batch() / "POST".

Thoughts?

Kijana Woodard

unread,
May 25, 2013, 12:06:58 PM5/25/13
to rav...@googlegroups.com

I'd rather post an update script _and_ an insert doc and let the server work out which to do. Less chatter with the client.

Jahmai Lay

unread,
May 25, 2013, 10:42:21 PM5/25/13
to rav...@googlegroups.com

Yeah I think AddOrUpdate needs to be its own (new) Patch command working on the same doc key, which would be easy to implement as a single request.

The problem I'm having is how to communicate 404 back to client for a Set, Inc Patch commands etc because at the moment the "POST" HTTP method doesn't respond with any errors at all for Patch commands, but the "PATCH" HTTP method does respond with 404 for Patch commands on missing docs.

My thoughts are that IDatabaseCommands.Patch should use the "PATCH" HTTP method and not the "POST" HTTP method - but that's something Oren needs to weigh in on I think.

Oren Eini (Ayende Rahien)

unread,
May 26, 2013, 4:37:45 AM5/26/13
to ravendb
That would work, yes.
Note that Batch() allows you to still return responses to the user
Reply all
Reply to author
Forward
0 new messages