[JAVA-3345] Get ID of last inserted document in a mongoDB w/ Java driver - WITH TYPED COLLECTION Created: 28/Jun/19 Updated: 01/Jul/19 Resolved: 01/Jul/19 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Command Operations |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Nagy László Zsolt | Assignee: | Ross Lawley |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Description |
|
For typed/generic collections, the @BsonId field is not recognized and changed by the driver. It seems impossible to get the object id of the last inserted document. For details, please see: https://stackoverflow.com/questions/54362159/get-id-of-last-inserted-document-in-a-mongodb-w-java-driver-with-typed-collec I'm asking this feature request because I did not get an answer for almost 6 months. I suppose that there is no good solution for this question other than changing the API. This change would probably be backwards compatible (I'm not 100% sure though). |
| Comments |
| Comment by Ross Lawley [ 01/Jul/19 ] |
|
Closing as a duplicate of This feature was added in 3.10. If you update your driver then you can take advantage of bug fixes and new features. All the best, Ross |
| Comment by Nagy László Zsolt [ 01/Jul/19 ] |
|
We are using 3.6.1 driver, and it does not populate that field for me:
<!-- https://mvnrepository.com/artifact/org.mongodb/mongo-java-driver -->
For this reason, we are still inserting documents instead of DTOs and we are reconstructing the DTO later. Here is an example:
public ForumMessageDTO addMessage(Long instituteGroupId, Long userId, String message, Document data) { Document d = new Document();
The declaration of the DTO starts with this:
public class ForumMessageDTO { public void setId(ObjectId id) { this.id = id; } ...
|
| Comment by Ross Lawley [ 01/Jul/19 ] |
|
Hi nagylzs, This looks to be a duplicate of Ross |