Closed visualist closed 6 years ago
With POST, the id of the created document is returned in the Location response header.
hmm.. I do need the ID in the hook addon, in Java. I don't see a way to get at the response headers from the HttpServerExchange exchange object passed into the hook() method. As far as response data goes, all I see is the getResponseCode() method on that object.
Sorry i didn't get your question.
The object returned by context.getDbOperationResult().getNewData()
should contain your _id
That is true of course only for write requests.
You can have a look at the SnooperHook example hook.
Thanks! I didn't think to look at the SnooperHook example.
dbOperationResult has a getNewId() method on it, but right now seems to be always null. Is that the future?
For future reference, here's basically what I did, without guards for NPEs etc:
String newId = newData.get("_id").asString().getValue();
Hi,
The getNewId() is supposed to work.
It is always null but when a new I'd is generated via a POST request.
Can you try? In case we mark this as a bug.
Yes, I will test this out and get back to you.
It is null for a POST to a collection. I snapped a copy of IntelliJ debug window, stopped from within my hook implementation. Look at the top line for getNewId(). The docid at the bottom is my own variable, obtained from digging into newData instead.
Also, I thought I was running 3.1.3 but I think I'm on a newer revision. My local repo is at: 101de1e7be4417b72d7c4eb2dd2430c19fc4bd9d MongoDB version 3.4.9
I pulled the latest from master, now I'm at 5cd6059017f178aee4b2a6ec69187dde00126ec6 but I'm still seeing the same null result for getNewId() method.
That's definitely a bug. I m going to fix it.
Thanks
@ujibang moving this to 3.2.1 ?
@ujibang is there a JIRA issue for this?
fixed in 842b2166534a581e81776339d64ace319e7bdb1a
Hi guys, me again. We've got Restheart working for us in production for all but this use case. Thanks for making such an excellent production! I'm running version 3.1.3.
I'm looking for the best/recommended way to obtain the ID of a newly-created document from within the hook() method (implements Hook) from this scenario:
I've tried various ways with inconsistent results, for example:
I was hoping there was a straightforward way to get ID & I'm must missing something. Thanks.