[SERVER-37341] get value from document using expression Created: 27/Sep/18 Updated: 04/Oct/18 Resolved: 04/Oct/18 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Aggregation Framework |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | yassine Karim [X] | Assignee: | Nick Brewer |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Participants: | |||||||||
| Description |
|
can we hav an aggregation operator like "$arrayElemAt" The <document> expression can be any valid expression as long as it resolves to a document. The <key> expression can be any valid expression as long as it resolves to a String.
Behavio Example -> Results { $elemAt: [ \{k1:"v1",k2:"v2"}, "k1" ] } -> "v1" { $elemAt: [ \{k1:"v1",k2:"v2"}, "k3" ] } -> null |
| Comments |
| Comment by Nick Brewer [ 04/Oct/18 ] |
|
yassineKarim I believe what you're describing is similar to the functionality described here: You can vote for that ticket, and follow along with it for updates. -Nick |
| Comment by yassine Karim [X] [ 04/Oct/18 ] |
|
nick.brewer the second parameter of arrayElemAt is an expression which resolve to an integer currently there is no way in mongo to access a sub Document using an expression as key inpput : { filed1:\{k1:v1,k2:v2}, field2:[k1,k2,k3] } in our aggregation pipeline we are intersted in unwinding on field 2 and getting the associated value on field1 , { filed1:v2, field2:k2 }, { field2:k3 }
our workaround is storing in an array field1 and using the unwind index to get the elements
Yassine |
| Comment by Nick Brewer [ 01/Oct/18 ] |
|
yassineKarim What you're describing does not appear to replicate the functionality of arrayElemAt, which uses an integer to return a value at a specific position. By comparison, what you're suggesting appears to use two equality statements. It would be useful to see what a sample document would look like in the example you've provided. Can you provide some more details on the specific task you're trying to accomplish? -Nick |