Details
-
New Feature
-
Status: Closed
-
Major - P3
-
Resolution: Done
-
2.1.1
-
None
-
Minor Change
-
Quint Iteration 4, Quint Iteration 5, Quint Iteration 6
Description
Aggregation $project stage should support $slice operator on array fields similar to $slice in projection and syntax similar to aggregation $substr operator:
{ "$project" : { "newArray" : { "$slice" : [ "$oldarray" , 10, 4 ] } } }
|
The above would take 4 elements from oldarray starting at position 10 (akin to "skipping first ten elements, as position is 0 based).
Original description:
If I have a document with an array of values in it, I would like to be able to project a slice of those values while aggregating.
{ title: "A doc",
|
intervals: [
|
{ value: 1, foo: true, bar: false },
|
{ value: 2, foo: false, bar: true },
|
{ value: 3, foo: true, bar: false}
|
]
|
}
|
$project with a $slice should work as expected:
{ $project : {
|
title: 1,
|
fewerIntervals: {intervals:{$slice:2}}
|
}
|
}
|
results in a pipelined document =>
{ title: "A doc",
|
fewerIntervals: [
|
{ value: 1, foo: true, bar: false },
|
{ value: 2, foo: false, bar: true }
|
]
|
}
|
Similarly, the remainder of the existing $slice syntax should work as expected.
{ $project : {
|
title: 1,
|
fewerIntervals: {intervals:{$slice:[1,1]}}
|
}
|
}
|
should produce
{ title: "A doc",
|
fewerIntervals: [
|
{ value: 2, foo: false, bar: true }
|
]
|
}
|
Attachments
Issue Links
- is duplicated by
-
SERVER-13400 Allow $slice operator in aggregation pipeline
-
- Closed
-
-
SERVER-15083 Allow projection of specific array elements by position
-
- Closed
-
- is related to
-
DRIVERS-234 Aggregation Builder Support for 3.2
-
- Closed
-
- related to
-
CSHARP-1368 Allow $slice operator in $project
-
- Closed
-
-
SERVER-4589 aggregation: need an array indexing operator
-
- Closed
-