[JAVA-2093] Shortcut for doc lookup by _id Created: 19/Jan/16 Updated: 19/Oct/16 Resolved: 05/Oct/16 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | API, Query Operations |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Blake Bauman | Assignee: | Jeffrey Yemin |
| Resolution: | Done | Votes: | 1 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
Very often, we need to simply look up a document by _id. What we have to do is use findOne() and updateOne() with eq("_id", <id value>). Since there's no official constant for "_id" we also have to define our own constant. This seems like something that can be easily provided in an official capacity. Ideally, this would be methods in MongoCollection like findById(<id value>), updateOneById(<id value>, <update>), and so on. |
| Comments |
| Comment by Githook User [ 05/Oct/16 ] | ||||||||||||||||||||||
|
Author: {u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}Message: | ||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 05/Oct/16 ] | ||||||||||||||||||||||
|
Blake, I'd be ok with an eqId or an overloaded eq method on Filters. I'll reopen the issue so that we can consider it further. | ||||||||||||||||||||||
| Comment by Blake Bauman [ 04/Oct/16 ] | ||||||||||||||||||||||
|
This is (essentially) what we're doing now. Yes, it is a bit fragile, so we were hoping for something official. Sort of a "get document X" or "update document X" where X is an _id value. If that's not possible, what about something in Filters such as Filters.eqId(value) (sort of like Projections.excludeId() and Projections.includeId())? | ||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 04/Oct/16 ] | ||||||||||||||||||||||
|
Closing as Won't Fix as applications can extend MongoCollection to add specialized methods. | ||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 04/Oct/16 ] | ||||||||||||||||||||||
|
MongoCollection is an interface so in principle applications can extend the interface to add extra methods, e.g.:
There's some fragility here because we do occasionally add methods to MongoCollection, and that technically breaks binary compatibility for anyone implementing that interface. But as long as the user takes responsibility for re-compiling code when upgrading or downgrading the driver, it can work. |