[SERVER-8951] Add $findChar or $indexOf operator for strings to find position of specific character (or substring) Created: 12/Mar/13 Updated: 22/Mar/17 Resolved: 29/Apr/16 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Aggregation Framework |
| Affects Version/s: | None |
| Fix Version/s: | 3.3.6 |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Asya Kamsky | Assignee: | Benjamin Murphy |
| Resolution: | Done | Votes: | 16 |
| Labels: | expression | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||||||||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||||||||||||||||||||||||||||||||||||||
| Sprint: | Query 12 (04/04/16), Query 13 (04/22/16), Query 14 (05/13/16) | ||||||||||||||||||||||||||||||||||||||||||||
| Participants: | |||||||||||||||||||||||||||||||||||||||||||||
| Description |
|
Syntax
Examples
Notes
Errors
Old Description |
| Comments |
| Comment by Benjamin Murphy [ 29/Apr/16 ] |
|
This ticket introduces $indexOfArray, $indexOfBytes, and $indexOfCP, with syntax in the description. It will need to be documented, and any drivers that support aggregation helpers will need to be updated to support it. |
| Comment by Githook User [ 29/Apr/16 ] |
|
Author: {u'username': u'benjaminmurphy', u'name': u'Benjamin Murphy', u'email': u'benjamin_murphy@me.com'}Message: |
| Comment by Asya Kamsky [ 19/Apr/16 ] |
|
This ticket is for expression for aggregation framework. $regex already exists and works in queries. If there is new functionality that's needed for queries that can't be done with $regex please open a new SERVER ticket with description of the use case/example of query that would be needed. |
| Comment by Shakir Sadikali [ 19/Apr/16 ] |
|
I'd like this added to more than the aggregation framework. In the general case, 2 functions
Have this work both in the aggregation framework and in "normal" queries (optionally support regex-like syntax?) This would be ideal, at least in the use-cases I've run into. |
| Comment by Andrew Shevchuk [ 24/Feb/16 ] |
|
Would be nice to have a string occurrence operator(less expensive than regex), like this: } ). |
| Comment by Charlie Swanson [ 15/Jan/16 ] |
|
I'll also note that (like other string manipulations) this gets tricky when dealing with UTF-8 characters. |
| Comment by Asya Kamsky [ 25/Sep/15 ] |
|
There is a workaround described here: |
| Comment by John A. De Goes [ 16/Jun/15 ] |
|
This would be very helpful to me. Although even more helpful is a way to convert a string into an array of characters (and an array of characters into a string), where of course a character is modeled as a length 1 string. Then the new array operators for mapping, filtering, and reducing could be used to perform string manipulation, too. The alternative is to have parallel versions of operators for strings and arrays. In general, you want to do the same sort of things on both (finding things, subsetting, filtering, etc.). |
| Comment by Yuri Finkelstein [ 03/Nov/13 ] |
|
I run into the same limitation with almost identical use case - need to extract the first token from a string where token boundaries are "." - whatever the symbol is does not matter. I agree with Scott that this class of problems requires a generic solution allowing for more powerful string manipulation in $project (and $group !). Perhaps - embed AWK or something like this |
| Comment by Asya Kamsky [ 16/Mar/13 ] |
|
The thing I was specifically trying to do was shorten a string into first "part" of it. I had server names as FQDNS server1.foo.bar.com server2.foo.bar.com, cfg1.foo.bar.com and I wanted to $project them to be just machine name (server1, server2, cfg1) - we have $substr for getting a substring but there is no way to find out where the first delimeter ('.' in this case) is. If there was an operator which returned the first occurrence of a character or a string in another string existed (say it was called $index or $find) I could |
| Comment by Scott Hernandez (Inactive) [ 16/Mar/13 ] |
|
What we need is an expression language, including string manipulation, which can execute functions and apply transformations/logic for projections and in other places. Can you provide a use case? "$index" doesn't make a lot of sense to me. |
| Comment by Asya Kamsky [ 16/Mar/13 ] |
|
To clarify, I mean for $project phase. Maybe $index is a better name (less overloading of meaning) |