[SERVER-1146] Partial matching on _id Created: 24/May/10 Updated: 16/Jan/11 Resolved: 16/Jan/11 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Roger Binns | Assignee: | Eliot Horowitz (Inactive) |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Participants: |
| Description |
|
I need to match part of an _id that was automatically generated on the server. This is for an administration tool letting the administrator specify part of an id to make things more usable for them. I don't care what the actual solution is, but there is currently no way to do this without visiting every row from a client. One example way would be using regex: find({_id: /.ab3c94./}) Currently regexes do not work against object id. |
| Comments |
| Comment by Eliot Horowitz (Inactive) [ 16/Jan/11 ] |
|
If you need that sort of queries, I don't think ObjectIds are appropriate. |
| Comment by Roger Binns [ 24/May/10 ] |
|
Using a $where like the following works. this._id.toString().match(/pattern/i) This is a reasonable solution and involves the server visiting every row. For improved performance, don't let users specify partial ids! /pattern/.match(this._id) does not work giving a confusing error message. The underlying cause is that _id is not actually a string. It is debatable what the server should do when getting the query in the original description (an error? a log message? silently say no match?) |